]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
f0706e82 JB |
2 | /* |
3 | * Copyright 2002-2005, Instant802 Networks, Inc. | |
4 | * Copyright 2005-2006, Devicescape Software, Inc. | |
5 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> | |
e8e4f528 | 6 | * Copyright 2017 Intel Deutschland GmbH |
d0a9123e | 7 | * Copyright (C) 2022 Intel Corporation |
f0706e82 JB |
8 | */ |
9 | ||
10 | #include <linux/kernel.h> | |
ff688089 | 11 | #include <linux/rtnetlink.h> |
3a9a231d | 12 | #include <linux/module.h> |
cc01f9b5 | 13 | #include <linux/slab.h> |
2c8dccc7 | 14 | #include "rate.h" |
f0706e82 | 15 | #include "ieee80211_i.h" |
4b7679a5 | 16 | #include "debugfs.h" |
f0706e82 JB |
17 | |
18 | struct rate_control_alg { | |
19 | struct list_head list; | |
631ad703 | 20 | const struct rate_control_ops *ops; |
f0706e82 JB |
21 | }; |
22 | ||
23 | static LIST_HEAD(rate_ctrl_algs); | |
24 | static DEFINE_MUTEX(rate_ctrl_mutex); | |
25 | ||
c21b39ac SB |
26 | static char *ieee80211_default_rc_algo = CONFIG_MAC80211_RC_DEFAULT; |
27 | module_param(ieee80211_default_rc_algo, charp, 0644); | |
28 | MODULE_PARM_DESC(ieee80211_default_rc_algo, | |
29 | "Default rate control algorithm for mac80211 to use"); | |
30 | ||
eb6d9293 DV |
31 | void rate_control_rate_init(struct sta_info *sta) |
32 | { | |
33 | struct ieee80211_local *local = sta->sdata->local; | |
34 | struct rate_control_ref *ref = sta->rate_ctrl; | |
35 | struct ieee80211_sta *ista = &sta->sta; | |
36 | void *priv_sta = sta->rate_ctrl_priv; | |
37 | struct ieee80211_supported_band *sband; | |
38 | struct ieee80211_chanctx_conf *chanctx_conf; | |
39 | ||
c71420db | 40 | ieee80211_sta_set_rx_nss(&sta->deflink); |
eb6d9293 DV |
41 | |
42 | if (!ref) | |
43 | return; | |
44 | ||
45 | rcu_read_lock(); | |
46 | ||
d0a9123e | 47 | chanctx_conf = rcu_dereference(sta->sdata->vif.bss_conf.chanctx_conf); |
eb6d9293 DV |
48 | if (WARN_ON(!chanctx_conf)) { |
49 | rcu_read_unlock(); | |
50 | return; | |
51 | } | |
52 | ||
53 | sband = local->hw.wiphy->bands[chanctx_conf->def.chan->band]; | |
54 | ||
cac8c526 TP |
55 | /* TODO: check for minstrel_s1g ? */ |
56 | if (sband->band == NL80211_BAND_S1GHZ) { | |
12bf8fad | 57 | ieee80211_s1g_sta_rate_init(sta); |
cac8c526 TP |
58 | rcu_read_unlock(); |
59 | return; | |
60 | } | |
61 | ||
eb6d9293 DV |
62 | spin_lock_bh(&sta->rate_ctrl_lock); |
63 | ref->ops->rate_init(ref->priv, sband, &chanctx_conf->def, ista, | |
64 | priv_sta); | |
65 | spin_unlock_bh(&sta->rate_ctrl_lock); | |
66 | rcu_read_unlock(); | |
67 | set_sta_flag(sta, WLAN_STA_RATE_CONTROL); | |
68 | } | |
69 | ||
18fb84d9 | 70 | void rate_control_tx_status(struct ieee80211_local *local, |
18fb84d9 FF |
71 | struct ieee80211_tx_status *st) |
72 | { | |
73 | struct rate_control_ref *ref = local->rate_ctrl; | |
74 | struct sta_info *sta = container_of(st->sta, struct sta_info, sta); | |
75 | void *priv_sta = sta->rate_ctrl_priv; | |
e5c0ee01 | 76 | struct ieee80211_supported_band *sband; |
18fb84d9 FF |
77 | |
78 | if (!ref || !test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) | |
79 | return; | |
80 | ||
e5c0ee01 JB |
81 | sband = local->hw.wiphy->bands[st->info->band]; |
82 | ||
18fb84d9 FF |
83 | spin_lock_bh(&sta->rate_ctrl_lock); |
84 | if (ref->ops->tx_status_ext) | |
85 | ref->ops->tx_status_ext(ref->priv, sband, priv_sta, st); | |
86 | else if (st->skb) | |
87 | ref->ops->tx_status(ref->priv, sband, st->sta, priv_sta, st->skb); | |
88 | else | |
89 | WARN_ON_ONCE(1); | |
90 | ||
91 | spin_unlock_bh(&sta->rate_ctrl_lock); | |
92 | } | |
93 | ||
eb6d9293 | 94 | void rate_control_rate_update(struct ieee80211_local *local, |
b4f85443 JB |
95 | struct ieee80211_supported_band *sband, |
96 | struct sta_info *sta, unsigned int link_id, | |
97 | u32 changed) | |
eb6d9293 DV |
98 | { |
99 | struct rate_control_ref *ref = local->rate_ctrl; | |
100 | struct ieee80211_sta *ista = &sta->sta; | |
101 | void *priv_sta = sta->rate_ctrl_priv; | |
102 | struct ieee80211_chanctx_conf *chanctx_conf; | |
103 | ||
b4f85443 JB |
104 | WARN_ON(link_id != 0); |
105 | ||
eb6d9293 DV |
106 | if (ref && ref->ops->rate_update) { |
107 | rcu_read_lock(); | |
108 | ||
d0a9123e | 109 | chanctx_conf = rcu_dereference(sta->sdata->vif.bss_conf.chanctx_conf); |
eb6d9293 DV |
110 | if (WARN_ON(!chanctx_conf)) { |
111 | rcu_read_unlock(); | |
112 | return; | |
113 | } | |
114 | ||
115 | spin_lock_bh(&sta->rate_ctrl_lock); | |
116 | ref->ops->rate_update(ref->priv, sband, &chanctx_conf->def, | |
117 | ista, priv_sta, changed); | |
118 | spin_unlock_bh(&sta->rate_ctrl_lock); | |
119 | rcu_read_unlock(); | |
120 | } | |
b4f85443 | 121 | |
eb6d9293 DV |
122 | drv_sta_rc_update(local, sta->sdata, &sta->sta, changed); |
123 | } | |
124 | ||
631ad703 | 125 | int ieee80211_rate_control_register(const struct rate_control_ops *ops) |
f0706e82 JB |
126 | { |
127 | struct rate_control_alg *alg; | |
128 | ||
ac71c691 JB |
129 | if (!ops->name) |
130 | return -EINVAL; | |
131 | ||
999acd9c JB |
132 | mutex_lock(&rate_ctrl_mutex); |
133 | list_for_each_entry(alg, &rate_ctrl_algs, list) { | |
134 | if (!strcmp(alg->ops->name, ops->name)) { | |
135 | /* don't register an algorithm twice */ | |
136 | WARN_ON(1); | |
b808ab16 | 137 | mutex_unlock(&rate_ctrl_mutex); |
999acd9c JB |
138 | return -EALREADY; |
139 | } | |
140 | } | |
141 | ||
dd00cc48 | 142 | alg = kzalloc(sizeof(*alg), GFP_KERNEL); |
f0706e82 | 143 | if (alg == NULL) { |
999acd9c | 144 | mutex_unlock(&rate_ctrl_mutex); |
f0706e82 JB |
145 | return -ENOMEM; |
146 | } | |
f0706e82 JB |
147 | alg->ops = ops; |
148 | ||
f0706e82 JB |
149 | list_add_tail(&alg->list, &rate_ctrl_algs); |
150 | mutex_unlock(&rate_ctrl_mutex); | |
151 | ||
152 | return 0; | |
153 | } | |
154 | EXPORT_SYMBOL(ieee80211_rate_control_register); | |
155 | ||
631ad703 | 156 | void ieee80211_rate_control_unregister(const struct rate_control_ops *ops) |
f0706e82 JB |
157 | { |
158 | struct rate_control_alg *alg; | |
159 | ||
160 | mutex_lock(&rate_ctrl_mutex); | |
161 | list_for_each_entry(alg, &rate_ctrl_algs, list) { | |
162 | if (alg->ops == ops) { | |
163 | list_del(&alg->list); | |
20880e89 | 164 | kfree(alg); |
f0706e82 JB |
165 | break; |
166 | } | |
167 | } | |
168 | mutex_unlock(&rate_ctrl_mutex); | |
f0706e82 JB |
169 | } |
170 | EXPORT_SYMBOL(ieee80211_rate_control_unregister); | |
171 | ||
631ad703 | 172 | static const struct rate_control_ops * |
f0706e82 JB |
173 | ieee80211_try_rate_control_ops_get(const char *name) |
174 | { | |
175 | struct rate_control_alg *alg; | |
631ad703 | 176 | const struct rate_control_ops *ops = NULL; |
f0706e82 | 177 | |
ac71c691 JB |
178 | if (!name) |
179 | return NULL; | |
180 | ||
f0706e82 JB |
181 | mutex_lock(&rate_ctrl_mutex); |
182 | list_for_each_entry(alg, &rate_ctrl_algs, list) { | |
cc01f9b5 JB |
183 | if (!strcmp(alg->ops->name, name)) { |
184 | ops = alg->ops; | |
185 | break; | |
186 | } | |
f0706e82 JB |
187 | } |
188 | mutex_unlock(&rate_ctrl_mutex); | |
189 | return ops; | |
190 | } | |
191 | ||
c21b39ac | 192 | /* Get the rate control algorithm. */ |
631ad703 | 193 | static const struct rate_control_ops * |
f0706e82 JB |
194 | ieee80211_rate_control_ops_get(const char *name) |
195 | { | |
631ad703 | 196 | const struct rate_control_ops *ops; |
c21b39ac | 197 | const char *alg_name; |
f0706e82 | 198 | |
b51d23e4 | 199 | kernel_param_lock(THIS_MODULE); |
ac71c691 | 200 | if (!name) |
c21b39ac SB |
201 | alg_name = ieee80211_default_rc_algo; |
202 | else | |
203 | alg_name = name; | |
ac71c691 | 204 | |
c21b39ac | 205 | ops = ieee80211_try_rate_control_ops_get(alg_name); |
c21b39ac SB |
206 | if (!ops && name) |
207 | /* try default if specific alg requested but not found */ | |
208 | ops = ieee80211_try_rate_control_ops_get(ieee80211_default_rc_algo); | |
209 | ||
93f56de2 MK |
210 | /* Note: check for > 0 is intentional to avoid clang warning */ |
211 | if (!ops && (strlen(CONFIG_MAC80211_RC_DEFAULT) > 0)) | |
212 | /* try built-in one if specific alg requested but not found */ | |
4b475898 | 213 | ops = ieee80211_try_rate_control_ops_get(CONFIG_MAC80211_RC_DEFAULT); |
93f56de2 | 214 | |
b51d23e4 | 215 | kernel_param_unlock(THIS_MODULE); |
4b475898 | 216 | |
f0706e82 JB |
217 | return ops; |
218 | } | |
219 | ||
4b7679a5 JB |
220 | #ifdef CONFIG_MAC80211_DEBUGFS |
221 | static ssize_t rcname_read(struct file *file, char __user *userbuf, | |
222 | size_t count, loff_t *ppos) | |
223 | { | |
224 | struct rate_control_ref *ref = file->private_data; | |
225 | int len = strlen(ref->ops->name); | |
226 | ||
227 | return simple_read_from_buffer(userbuf, count, ppos, | |
228 | ref->ops->name, len); | |
229 | } | |
230 | ||
6cb5f3ea | 231 | const struct file_operations rcname_ops = { |
4b7679a5 | 232 | .read = rcname_read, |
234e3405 | 233 | .open = simple_open, |
6038f373 | 234 | .llseek = default_llseek, |
4b7679a5 JB |
235 | }; |
236 | #endif | |
237 | ||
6cb5f3ea JB |
238 | static struct rate_control_ref * |
239 | rate_control_alloc(const char *name, struct ieee80211_local *local) | |
f0706e82 JB |
240 | { |
241 | struct rate_control_ref *ref; | |
242 | ||
243 | ref = kmalloc(sizeof(struct rate_control_ref), GFP_KERNEL); | |
244 | if (!ref) | |
cc01f9b5 | 245 | return NULL; |
f0706e82 JB |
246 | ref->ops = ieee80211_rate_control_ops_get(name); |
247 | if (!ref->ops) | |
cc01f9b5 | 248 | goto free; |
4b7679a5 | 249 | |
6cb5f3ea | 250 | ref->priv = ref->ops->alloc(&local->hw); |
f0706e82 | 251 | if (!ref->priv) |
cc01f9b5 | 252 | goto free; |
f0706e82 JB |
253 | return ref; |
254 | ||
cc01f9b5 | 255 | free: |
f0706e82 | 256 | kfree(ref); |
f0706e82 JB |
257 | return NULL; |
258 | } | |
259 | ||
a858958b JB |
260 | static void rate_control_free(struct ieee80211_local *local, |
261 | struct rate_control_ref *ctrl_ref) | |
f0706e82 | 262 | { |
f0706e82 | 263 | ctrl_ref->ops->free(ctrl_ref->priv); |
4b7679a5 JB |
264 | |
265 | #ifdef CONFIG_MAC80211_DEBUGFS | |
a858958b JB |
266 | debugfs_remove_recursive(local->debugfs.rcdir); |
267 | local->debugfs.rcdir = NULL; | |
4b7679a5 JB |
268 | #endif |
269 | ||
f0706e82 JB |
270 | kfree(ctrl_ref); |
271 | } | |
272 | ||
de03f8ac | 273 | void ieee80211_check_rate_mask(struct ieee80211_link_data *link) |
e8e4f528 | 274 | { |
de03f8ac | 275 | struct ieee80211_sub_if_data *sdata = link->sdata; |
e8e4f528 JB |
276 | struct ieee80211_local *local = sdata->local; |
277 | struct ieee80211_supported_band *sband; | |
de03f8ac | 278 | u32 user_mask, basic_rates = link->conf->basic_rates; |
e8e4f528 JB |
279 | enum nl80211_band band; |
280 | ||
de03f8ac | 281 | if (WARN_ON(!link->conf->chandef.chan)) |
e8e4f528 JB |
282 | return; |
283 | ||
de03f8ac | 284 | band = link->conf->chandef.chan->band; |
1821f8b3 TP |
285 | if (band == NL80211_BAND_S1GHZ) { |
286 | /* TODO */ | |
287 | return; | |
288 | } | |
289 | ||
e8e4f528 JB |
290 | if (WARN_ON_ONCE(!basic_rates)) |
291 | return; | |
292 | ||
e8e4f528 JB |
293 | user_mask = sdata->rc_rateidx_mask[band]; |
294 | sband = local->hw.wiphy->bands[band]; | |
295 | ||
296 | if (user_mask & basic_rates) | |
297 | return; | |
298 | ||
299 | sdata_dbg(sdata, | |
300 | "no overlap between basic rates (0x%x) and user mask (0x%x on band %d) - clearing the latter", | |
301 | basic_rates, user_mask, band); | |
302 | sdata->rc_rateidx_mask[band] = (1 << sband->n_bitrates) - 1; | |
303 | } | |
304 | ||
b6f35301 | 305 | static bool rc_no_data_or_no_ack_use_min(struct ieee80211_tx_rate_control *txrc) |
4c6d4f5c LR |
306 | { |
307 | struct sk_buff *skb = txrc->skb; | |
4c6d4f5c | 308 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
4c6d4f5c | 309 | |
b6f35301 RM |
310 | return (info->flags & (IEEE80211_TX_CTL_NO_ACK | |
311 | IEEE80211_TX_CTL_USE_MINRATE)) || | |
4e6c78bd | 312 | !ieee80211_is_tx_data(skb); |
4c6d4f5c LR |
313 | } |
314 | ||
1821f8b3 TP |
315 | static void rc_send_low_basicrate(struct ieee80211_tx_rate *rate, |
316 | u32 basic_rates, | |
8f0729b1 | 317 | struct ieee80211_supported_band *sband) |
e00cfce0 JM |
318 | { |
319 | u8 i; | |
320 | ||
1821f8b3 TP |
321 | if (sband->band == NL80211_BAND_S1GHZ) { |
322 | /* TODO */ | |
323 | rate->flags |= IEEE80211_TX_RC_S1G_MCS; | |
324 | rate->idx = 0; | |
325 | return; | |
326 | } | |
327 | ||
e00cfce0 JM |
328 | if (basic_rates == 0) |
329 | return; /* assume basic rates unknown and accept rate */ | |
1821f8b3 | 330 | if (rate->idx < 0) |
e00cfce0 | 331 | return; |
1821f8b3 | 332 | if (basic_rates & (1 << rate->idx)) |
e00cfce0 JM |
333 | return; /* selected rate is a basic rate */ |
334 | ||
1821f8b3 | 335 | for (i = rate->idx + 1; i <= sband->n_bitrates; i++) { |
e00cfce0 | 336 | if (basic_rates & (1 << i)) { |
1821f8b3 | 337 | rate->idx = i; |
e00cfce0 JM |
338 | return; |
339 | } | |
340 | } | |
341 | ||
342 | /* could not find a basic rate; use original selection */ | |
343 | } | |
344 | ||
2103dec1 SW |
345 | static void __rate_control_send_low(struct ieee80211_hw *hw, |
346 | struct ieee80211_supported_band *sband, | |
347 | struct ieee80211_sta *sta, | |
1d2d350b AO |
348 | struct ieee80211_tx_info *info, |
349 | u32 rate_mask) | |
aad14ceb RM |
350 | { |
351 | int i; | |
2103dec1 SW |
352 | u32 rate_flags = |
353 | ieee80211_chandef_rate_flags(&hw->conf.chandef); | |
aad14ceb | 354 | |
1821f8b3 TP |
355 | if (sband->band == NL80211_BAND_S1GHZ) { |
356 | info->control.rates[0].flags |= IEEE80211_TX_RC_S1G_MCS; | |
357 | info->control.rates[0].idx = 0; | |
358 | return; | |
359 | } | |
360 | ||
57fbcce3 | 361 | if ((sband->band == NL80211_BAND_2GHZ) && |
2103dec1 SW |
362 | (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)) |
363 | rate_flags |= IEEE80211_RATE_ERP_G; | |
364 | ||
365 | info->control.rates[0].idx = 0; | |
aad14ceb | 366 | for (i = 0; i < sband->n_bitrates; i++) { |
1d2d350b AO |
367 | if (!(rate_mask & BIT(i))) |
368 | continue; | |
369 | ||
1431fcb7 AO |
370 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) |
371 | continue; | |
372 | ||
2103dec1 | 373 | if (!rate_supported(sta, sband->band, i)) |
aad14ceb RM |
374 | continue; |
375 | ||
2103dec1 SW |
376 | info->control.rates[0].idx = i; |
377 | break; | |
aad14ceb | 378 | } |
0e5c371a | 379 | WARN_ONCE(i == sband->n_bitrates, |
163a7cdd JB |
380 | "no supported rates for sta %pM (0x%x, band %d) in rate_mask 0x%x with flags 0x%x\n", |
381 | sta ? sta->addr : NULL, | |
046d2e7c | 382 | sta ? sta->deflink.supp_rates[sband->band] : -1, |
163a7cdd | 383 | sband->band, |
0e5c371a | 384 | rate_mask, rate_flags); |
0d528d85 FF |
385 | |
386 | info->control.rates[0].count = | |
387 | (info->flags & IEEE80211_TX_CTL_NO_ACK) ? | |
388 | 1 : hw->max_rate_tries; | |
389 | ||
390 | info->control.skip_table = 1; | |
391 | } | |
392 | ||
aad14ceb | 393 | |
1e87fec9 JB |
394 | static bool rate_control_send_low(struct ieee80211_sta *pubsta, |
395 | struct ieee80211_tx_rate_control *txrc) | |
4c6d4f5c LR |
396 | { |
397 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); | |
dd5b4cc7 | 398 | struct ieee80211_supported_band *sband = txrc->sband; |
06703079 | 399 | struct sta_info *sta; |
dd5b4cc7 | 400 | int mcast_rate; |
06703079 | 401 | bool use_basicrate = false; |
4c6d4f5c | 402 | |
1e87fec9 | 403 | if (!pubsta || rc_no_data_or_no_ack_use_min(txrc)) { |
1d2d350b AO |
404 | __rate_control_send_low(txrc->hw, sband, pubsta, info, |
405 | txrc->rate_idx_mask); | |
0d528d85 | 406 | |
06703079 | 407 | if (!pubsta && txrc->bss) { |
dd5b4cc7 FF |
408 | mcast_rate = txrc->bss_conf->mcast_rate[sband->band]; |
409 | if (mcast_rate > 0) { | |
410 | info->control.rates[0].idx = mcast_rate - 1; | |
411 | return true; | |
412 | } | |
06703079 CYY |
413 | use_basicrate = true; |
414 | } else if (pubsta) { | |
415 | sta = container_of(pubsta, struct sta_info, sta); | |
416 | if (ieee80211_vif_is_mesh(&sta->sdata->vif)) | |
417 | use_basicrate = true; | |
418 | } | |
dd5b4cc7 | 419 | |
06703079 | 420 | if (use_basicrate) |
1821f8b3 | 421 | rc_send_low_basicrate(&info->control.rates[0], |
e00cfce0 | 422 | txrc->bss_conf->basic_rates, |
dd5b4cc7 | 423 | sband); |
06703079 | 424 | |
4c6d4f5c LR |
425 | return true; |
426 | } | |
427 | return false; | |
428 | } | |
4c6d4f5c | 429 | |
90c66bd2 | 430 | static bool rate_idx_match_legacy_mask(s8 *rate_idx, int n_bitrates, u32 mask) |
37eb0b16 JM |
431 | { |
432 | int j; | |
433 | ||
434 | /* See whether the selected rate or anything below it is allowed. */ | |
90c66bd2 | 435 | for (j = *rate_idx; j >= 0; j--) { |
37eb0b16 JM |
436 | if (mask & (1 << j)) { |
437 | /* Okay, found a suitable rate. Use it. */ | |
90c66bd2 | 438 | *rate_idx = j; |
19468413 | 439 | return true; |
37eb0b16 JM |
440 | } |
441 | } | |
442 | ||
443 | /* Try to find a higher rate that would be allowed */ | |
90c66bd2 | 444 | for (j = *rate_idx + 1; j < n_bitrates; j++) { |
37eb0b16 JM |
445 | if (mask & (1 << j)) { |
446 | /* Okay, found a suitable rate. Use it. */ | |
90c66bd2 | 447 | *rate_idx = j; |
19468413 SW |
448 | return true; |
449 | } | |
450 | } | |
451 | return false; | |
452 | } | |
453 | ||
90c66bd2 | 454 | static bool rate_idx_match_mcs_mask(s8 *rate_idx, u8 *mcs_mask) |
19468413 SW |
455 | { |
456 | int i, j; | |
457 | int ridx, rbit; | |
458 | ||
90c66bd2 LB |
459 | ridx = *rate_idx / 8; |
460 | rbit = *rate_idx % 8; | |
19468413 SW |
461 | |
462 | /* sanity check */ | |
910570b5 | 463 | if (ridx < 0 || ridx >= IEEE80211_HT_MCS_MASK_LEN) |
19468413 SW |
464 | return false; |
465 | ||
466 | /* See whether the selected rate or anything below it is allowed. */ | |
467 | for (i = ridx; i >= 0; i--) { | |
468 | for (j = rbit; j >= 0; j--) | |
469 | if (mcs_mask[i] & BIT(j)) { | |
90c66bd2 | 470 | *rate_idx = i * 8 + j; |
19468413 SW |
471 | return true; |
472 | } | |
473 | rbit = 7; | |
474 | } | |
475 | ||
476 | /* Try to find a higher rate that would be allowed */ | |
90c66bd2 LB |
477 | ridx = (*rate_idx + 1) / 8; |
478 | rbit = (*rate_idx + 1) % 8; | |
19468413 SW |
479 | |
480 | for (i = ridx; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
481 | for (j = rbit; j < 8; j++) | |
482 | if (mcs_mask[i] & BIT(j)) { | |
90c66bd2 | 483 | *rate_idx = i * 8 + j; |
19468413 SW |
484 | return true; |
485 | } | |
486 | rbit = 0; | |
487 | } | |
488 | return false; | |
489 | } | |
490 | ||
b119ad6e LB |
491 | static bool rate_idx_match_vht_mcs_mask(s8 *rate_idx, u16 *vht_mask) |
492 | { | |
493 | int i, j; | |
494 | int ridx, rbit; | |
495 | ||
496 | ridx = *rate_idx >> 4; | |
497 | rbit = *rate_idx & 0xf; | |
498 | ||
499 | if (ridx < 0 || ridx >= NL80211_VHT_NSS_MAX) | |
500 | return false; | |
19468413 | 501 | |
b119ad6e LB |
502 | /* See whether the selected rate or anything below it is allowed. */ |
503 | for (i = ridx; i >= 0; i--) { | |
504 | for (j = rbit; j >= 0; j--) { | |
505 | if (vht_mask[i] & BIT(j)) { | |
506 | *rate_idx = (i << 4) | j; | |
507 | return true; | |
508 | } | |
509 | } | |
510 | rbit = 15; | |
511 | } | |
512 | ||
513 | /* Try to find a higher rate that would be allowed */ | |
514 | ridx = (*rate_idx + 1) >> 4; | |
515 | rbit = (*rate_idx + 1) & 0xf; | |
516 | ||
517 | for (i = ridx; i < NL80211_VHT_NSS_MAX; i++) { | |
518 | for (j = rbit; j < 16; j++) { | |
519 | if (vht_mask[i] & BIT(j)) { | |
520 | *rate_idx = (i << 4) | j; | |
521 | return true; | |
522 | } | |
523 | } | |
524 | rbit = 0; | |
525 | } | |
526 | return false; | |
527 | } | |
19468413 | 528 | |
90c66bd2 | 529 | static void rate_idx_match_mask(s8 *rate_idx, u16 *rate_flags, |
0d528d85 FF |
530 | struct ieee80211_supported_band *sband, |
531 | enum nl80211_chan_width chan_width, | |
19468413 | 532 | u32 mask, |
b119ad6e LB |
533 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN], |
534 | u16 vht_mask[NL80211_VHT_NSS_MAX]) | |
19468413 | 535 | { |
b119ad6e LB |
536 | if (*rate_flags & IEEE80211_TX_RC_VHT_MCS) { |
537 | /* handle VHT rates */ | |
538 | if (rate_idx_match_vht_mcs_mask(rate_idx, vht_mask)) | |
539 | return; | |
540 | ||
541 | *rate_idx = 0; | |
542 | /* keep protection flags */ | |
543 | *rate_flags &= (IEEE80211_TX_RC_USE_RTS_CTS | | |
544 | IEEE80211_TX_RC_USE_CTS_PROTECT | | |
545 | IEEE80211_TX_RC_USE_SHORT_PREAMBLE); | |
546 | ||
547 | *rate_flags |= IEEE80211_TX_RC_MCS; | |
548 | if (chan_width == NL80211_CHAN_WIDTH_40) | |
549 | *rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; | |
550 | ||
551 | if (rate_idx_match_mcs_mask(rate_idx, mcs_mask)) | |
552 | return; | |
553 | ||
554 | /* also try the legacy rates. */ | |
555 | *rate_flags &= ~(IEEE80211_TX_RC_MCS | | |
556 | IEEE80211_TX_RC_40_MHZ_WIDTH); | |
557 | if (rate_idx_match_legacy_mask(rate_idx, sband->n_bitrates, | |
558 | mask)) | |
559 | return; | |
560 | } else if (*rate_flags & IEEE80211_TX_RC_MCS) { | |
561 | /* handle HT rates */ | |
90c66bd2 | 562 | if (rate_idx_match_mcs_mask(rate_idx, mcs_mask)) |
19468413 SW |
563 | return; |
564 | ||
565 | /* also try the legacy rates. */ | |
90c66bd2 | 566 | *rate_idx = 0; |
19468413 | 567 | /* keep protection flags */ |
90c66bd2 LB |
568 | *rate_flags &= (IEEE80211_TX_RC_USE_RTS_CTS | |
569 | IEEE80211_TX_RC_USE_CTS_PROTECT | | |
570 | IEEE80211_TX_RC_USE_SHORT_PREAMBLE); | |
571 | if (rate_idx_match_legacy_mask(rate_idx, sband->n_bitrates, | |
572 | mask)) | |
19468413 | 573 | return; |
b119ad6e | 574 | } else { |
19468413 | 575 | /* handle legacy rates */ |
90c66bd2 LB |
576 | if (rate_idx_match_legacy_mask(rate_idx, sband->n_bitrates, |
577 | mask)) | |
19468413 SW |
578 | return; |
579 | ||
580 | /* if HT BSS, and we handle a data frame, also try HT rates */ | |
0418a445 SW |
581 | switch (chan_width) { |
582 | case NL80211_CHAN_WIDTH_20_NOHT: | |
583 | case NL80211_CHAN_WIDTH_5: | |
584 | case NL80211_CHAN_WIDTH_10: | |
19468413 | 585 | return; |
0418a445 SW |
586 | default: |
587 | break; | |
588 | } | |
19468413 | 589 | |
90c66bd2 | 590 | *rate_idx = 0; |
19468413 | 591 | /* keep protection flags */ |
90c66bd2 LB |
592 | *rate_flags &= (IEEE80211_TX_RC_USE_RTS_CTS | |
593 | IEEE80211_TX_RC_USE_CTS_PROTECT | | |
594 | IEEE80211_TX_RC_USE_SHORT_PREAMBLE); | |
19468413 | 595 | |
90c66bd2 | 596 | *rate_flags |= IEEE80211_TX_RC_MCS; |
19468413 | 597 | |
0d528d85 | 598 | if (chan_width == NL80211_CHAN_WIDTH_40) |
90c66bd2 | 599 | *rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
19468413 | 600 | |
90c66bd2 | 601 | if (rate_idx_match_mcs_mask(rate_idx, mcs_mask)) |
37eb0b16 | 602 | return; |
37eb0b16 JM |
603 | } |
604 | ||
605 | /* | |
606 | * Uh.. No suitable rate exists. This should not really happen with | |
607 | * sane TX rate mask configurations. However, should someone manage to | |
608 | * configure supported rates and TX rate mask in incompatible way, | |
609 | * allow the frame to be transmitted with whatever the rate control | |
610 | * selected. | |
611 | */ | |
612 | } | |
613 | ||
0d528d85 FF |
614 | static void rate_fixup_ratelist(struct ieee80211_vif *vif, |
615 | struct ieee80211_supported_band *sband, | |
616 | struct ieee80211_tx_info *info, | |
617 | struct ieee80211_tx_rate *rates, | |
618 | int max_rates) | |
619 | { | |
620 | struct ieee80211_rate *rate; | |
621 | bool inval = false; | |
622 | int i; | |
623 | ||
624 | /* | |
625 | * Set up the RTS/CTS rate as the fastest basic rate | |
626 | * that is not faster than the data rate unless there | |
627 | * is no basic rate slower than the data rate, in which | |
628 | * case we pick the slowest basic rate | |
629 | * | |
630 | * XXX: Should this check all retry rates? | |
631 | */ | |
336004e2 FF |
632 | if (!(rates[0].flags & |
633 | (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))) { | |
0d528d85 | 634 | u32 basic_rates = vif->bss_conf.basic_rates; |
c7abf25a | 635 | s8 baserate = basic_rates ? ffs(basic_rates) - 1 : 0; |
0d528d85 FF |
636 | |
637 | rate = &sband->bitrates[rates[0].idx]; | |
638 | ||
639 | for (i = 0; i < sband->n_bitrates; i++) { | |
640 | /* must be a basic rate */ | |
641 | if (!(basic_rates & BIT(i))) | |
642 | continue; | |
643 | /* must not be faster than the data rate */ | |
644 | if (sband->bitrates[i].bitrate > rate->bitrate) | |
645 | continue; | |
646 | /* maximum */ | |
647 | if (sband->bitrates[baserate].bitrate < | |
648 | sband->bitrates[i].bitrate) | |
649 | baserate = i; | |
650 | } | |
651 | ||
652 | info->control.rts_cts_rate_idx = baserate; | |
653 | } | |
654 | ||
655 | for (i = 0; i < max_rates; i++) { | |
656 | /* | |
657 | * make sure there's no valid rate following | |
658 | * an invalid one, just in case drivers don't | |
659 | * take the API seriously to stop at -1. | |
660 | */ | |
661 | if (inval) { | |
662 | rates[i].idx = -1; | |
663 | continue; | |
664 | } | |
665 | if (rates[i].idx < 0) { | |
666 | inval = true; | |
667 | continue; | |
668 | } | |
669 | ||
670 | /* | |
671 | * For now assume MCS is already set up correctly, this | |
672 | * needs to be fixed. | |
673 | */ | |
674 | if (rates[i].flags & IEEE80211_TX_RC_MCS) { | |
675 | WARN_ON(rates[i].idx > 76); | |
676 | ||
677 | if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) && | |
678 | info->control.use_cts_prot) | |
679 | rates[i].flags |= | |
680 | IEEE80211_TX_RC_USE_CTS_PROTECT; | |
681 | continue; | |
682 | } | |
683 | ||
684 | if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) { | |
685 | WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9); | |
686 | continue; | |
687 | } | |
688 | ||
689 | /* set up RTS protection if desired */ | |
690 | if (info->control.use_rts) { | |
691 | rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS; | |
692 | info->control.use_cts_prot = false; | |
693 | } | |
694 | ||
695 | /* RC is busted */ | |
696 | if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) { | |
697 | rates[i].idx = -1; | |
698 | continue; | |
699 | } | |
700 | ||
701 | rate = &sband->bitrates[rates[i].idx]; | |
702 | ||
703 | /* set up short preamble */ | |
704 | if (info->control.short_preamble && | |
705 | rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) | |
706 | rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE; | |
707 | ||
708 | /* set up G protection */ | |
709 | if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) && | |
710 | info->control.use_cts_prot && | |
711 | rate->flags & IEEE80211_RATE_ERP_G) | |
712 | rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT; | |
713 | } | |
714 | } | |
715 | ||
716 | ||
717 | static void rate_control_fill_sta_table(struct ieee80211_sta *sta, | |
718 | struct ieee80211_tx_info *info, | |
719 | struct ieee80211_tx_rate *rates, | |
720 | int max_rates) | |
721 | { | |
722 | struct ieee80211_sta_rates *ratetbl = NULL; | |
723 | int i; | |
724 | ||
725 | if (sta && !info->control.skip_table) | |
726 | ratetbl = rcu_dereference(sta->rates); | |
727 | ||
728 | /* Fill remaining rate slots with data from the sta rate table. */ | |
729 | max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE); | |
730 | for (i = 0; i < max_rates; i++) { | |
731 | if (i < ARRAY_SIZE(info->control.rates) && | |
732 | info->control.rates[i].idx >= 0 && | |
733 | info->control.rates[i].count) { | |
734 | if (rates != info->control.rates) | |
735 | rates[i] = info->control.rates[i]; | |
736 | } else if (ratetbl) { | |
737 | rates[i].idx = ratetbl->rate[i].idx; | |
738 | rates[i].flags = ratetbl->rate[i].flags; | |
739 | if (info->control.use_rts) | |
740 | rates[i].count = ratetbl->rate[i].count_rts; | |
741 | else if (info->control.use_cts_prot) | |
742 | rates[i].count = ratetbl->rate[i].count_cts; | |
743 | else | |
744 | rates[i].count = ratetbl->rate[i].count; | |
745 | } else { | |
746 | rates[i].idx = -1; | |
747 | rates[i].count = 0; | |
748 | } | |
749 | ||
750 | if (rates[i].idx < 0 || !rates[i].count) | |
751 | break; | |
752 | } | |
753 | } | |
754 | ||
90c66bd2 LB |
755 | static bool rate_control_cap_mask(struct ieee80211_sub_if_data *sdata, |
756 | struct ieee80211_supported_band *sband, | |
757 | struct ieee80211_sta *sta, u32 *mask, | |
b119ad6e LB |
758 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN], |
759 | u16 vht_mask[NL80211_VHT_NSS_MAX]) | |
90c66bd2 LB |
760 | { |
761 | u32 i, flags; | |
762 | ||
763 | *mask = sdata->rc_rateidx_mask[sband->band]; | |
764 | flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); | |
765 | for (i = 0; i < sband->n_bitrates; i++) { | |
766 | if ((flags & sband->bitrates[i].flags) != flags) | |
767 | *mask &= ~BIT(i); | |
768 | } | |
769 | ||
770 | if (*mask == (1 << sband->n_bitrates) - 1 && | |
b119ad6e LB |
771 | !sdata->rc_has_mcs_mask[sband->band] && |
772 | !sdata->rc_has_vht_mcs_mask[sband->band]) | |
90c66bd2 LB |
773 | return false; |
774 | ||
775 | if (sdata->rc_has_mcs_mask[sband->band]) | |
776 | memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[sband->band], | |
777 | IEEE80211_HT_MCS_MASK_LEN); | |
778 | else | |
779 | memset(mcs_mask, 0xff, IEEE80211_HT_MCS_MASK_LEN); | |
780 | ||
b119ad6e LB |
781 | if (sdata->rc_has_vht_mcs_mask[sband->band]) |
782 | memcpy(vht_mask, sdata->rc_rateidx_vht_mcs_mask[sband->band], | |
783 | sizeof(u16) * NL80211_VHT_NSS_MAX); | |
784 | else | |
785 | memset(vht_mask, 0xff, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
786 | ||
90c66bd2 | 787 | if (sta) { |
b119ad6e LB |
788 | __le16 sta_vht_cap; |
789 | u16 sta_vht_mask[NL80211_VHT_NSS_MAX]; | |
790 | ||
90c66bd2 | 791 | /* Filter out rates that the STA does not support */ |
046d2e7c | 792 | *mask &= sta->deflink.supp_rates[sband->band]; |
98a1f828 | 793 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
046d2e7c | 794 | mcs_mask[i] &= sta->deflink.ht_cap.mcs.rx_mask[i]; |
b119ad6e | 795 | |
046d2e7c | 796 | sta_vht_cap = sta->deflink.vht_cap.vht_mcs.rx_mcs_map; |
b119ad6e LB |
797 | ieee80211_get_vht_mask_from_cap(sta_vht_cap, sta_vht_mask); |
798 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
799 | vht_mask[i] &= sta_vht_mask[i]; | |
90c66bd2 LB |
800 | } |
801 | ||
802 | return true; | |
803 | } | |
804 | ||
e910867b LB |
805 | static void |
806 | rate_control_apply_mask_ratetbl(struct sta_info *sta, | |
807 | struct ieee80211_supported_band *sband, | |
808 | struct ieee80211_sta_rates *rates) | |
809 | { | |
810 | int i; | |
811 | u32 mask; | |
812 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]; | |
b119ad6e | 813 | u16 vht_mask[NL80211_VHT_NSS_MAX]; |
e910867b LB |
814 | enum nl80211_chan_width chan_width; |
815 | ||
816 | if (!rate_control_cap_mask(sta->sdata, sband, &sta->sta, &mask, | |
b119ad6e | 817 | mcs_mask, vht_mask)) |
e910867b LB |
818 | return; |
819 | ||
820 | chan_width = sta->sdata->vif.bss_conf.chandef.width; | |
821 | for (i = 0; i < IEEE80211_TX_RATE_TABLE_SIZE; i++) { | |
822 | if (rates->rate[i].idx < 0) | |
823 | break; | |
824 | ||
825 | rate_idx_match_mask(&rates->rate[i].idx, &rates->rate[i].flags, | |
b119ad6e LB |
826 | sband, chan_width, mask, mcs_mask, |
827 | vht_mask); | |
e910867b LB |
828 | } |
829 | } | |
830 | ||
0d528d85 FF |
831 | static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata, |
832 | struct ieee80211_sta *sta, | |
833 | struct ieee80211_supported_band *sband, | |
0d528d85 FF |
834 | struct ieee80211_tx_rate *rates, |
835 | int max_rates) | |
836 | { | |
837 | enum nl80211_chan_width chan_width; | |
838 | u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN]; | |
0d528d85 | 839 | u32 mask; |
b119ad6e | 840 | u16 rate_flags, vht_mask[NL80211_VHT_NSS_MAX]; |
0d528d85 FF |
841 | int i; |
842 | ||
843 | /* | |
844 | * Try to enforce the rateidx mask the user wanted. skip this if the | |
845 | * default mask (allow all rates) is used to save some processing for | |
846 | * the common case. | |
847 | */ | |
b119ad6e LB |
848 | if (!rate_control_cap_mask(sdata, sband, sta, &mask, mcs_mask, |
849 | vht_mask)) | |
0d528d85 FF |
850 | return; |
851 | ||
0d528d85 FF |
852 | /* |
853 | * Make sure the rate index selected for each TX rate is | |
854 | * included in the configured mask and change the rate indexes | |
855 | * if needed. | |
856 | */ | |
857 | chan_width = sdata->vif.bss_conf.chandef.width; | |
858 | for (i = 0; i < max_rates; i++) { | |
859 | /* Skip invalid rates */ | |
860 | if (rates[i].idx < 0) | |
861 | break; | |
862 | ||
90c66bd2 LB |
863 | rate_flags = rates[i].flags; |
864 | rate_idx_match_mask(&rates[i].idx, &rate_flags, sband, | |
b119ad6e | 865 | chan_width, mask, mcs_mask, vht_mask); |
90c66bd2 | 866 | rates[i].flags = rate_flags; |
0d528d85 FF |
867 | } |
868 | } | |
869 | ||
870 | void ieee80211_get_tx_rates(struct ieee80211_vif *vif, | |
871 | struct ieee80211_sta *sta, | |
872 | struct sk_buff *skb, | |
873 | struct ieee80211_tx_rate *dest, | |
874 | int max_rates) | |
875 | { | |
876 | struct ieee80211_sub_if_data *sdata; | |
0d528d85 FF |
877 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
878 | struct ieee80211_supported_band *sband; | |
879 | ||
880 | rate_control_fill_sta_table(sta, info, dest, max_rates); | |
881 | ||
882 | if (!vif) | |
883 | return; | |
884 | ||
885 | sdata = vif_to_sdata(vif); | |
886 | sband = sdata->local->hw.wiphy->bands[info->band]; | |
887 | ||
3187ba0c | 888 | if (ieee80211_is_tx_data(skb)) |
35225eb7 | 889 | rate_control_apply_mask(sdata, sta, sband, dest, max_rates); |
0d528d85 FF |
890 | |
891 | if (dest[0].idx < 0) | |
1d2d350b AO |
892 | __rate_control_send_low(&sdata->local->hw, sband, sta, info, |
893 | sdata->rc_rateidx_mask[info->band]); | |
0d528d85 FF |
894 | |
895 | if (sta) | |
896 | rate_fixup_ratelist(vif, sband, info, dest, max_rates); | |
897 | } | |
898 | EXPORT_SYMBOL(ieee80211_get_tx_rates); | |
899 | ||
4b7679a5 | 900 | void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, |
e6a9854b JB |
901 | struct sta_info *sta, |
902 | struct ieee80211_tx_rate_control *txrc) | |
1abbe498 | 903 | { |
4b7679a5 JB |
904 | struct rate_control_ref *ref = sdata->local->rate_ctrl; |
905 | void *priv_sta = NULL; | |
906 | struct ieee80211_sta *ista = NULL; | |
e6a9854b | 907 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb); |
1abbe498 | 908 | int i; |
1abbe498 | 909 | |
e6a9854b JB |
910 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { |
911 | info->control.rates[i].idx = -1; | |
912 | info->control.rates[i].flags = 0; | |
8617b093 | 913 | info->control.rates[i].count = 0; |
e6a9854b JB |
914 | } |
915 | ||
583a7a34 | 916 | if (rate_control_send_low(sta ? &sta->sta : NULL, txrc)) |
5affcd6b JO |
917 | return; |
918 | ||
583a7a34 | 919 | if (ieee80211_hw_check(&sdata->local->hw, HAS_RATE_CONTROL)) |
1e87fec9 JB |
920 | return; |
921 | ||
bd718fc1 JB |
922 | if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) { |
923 | ista = &sta->sta; | |
924 | priv_sta = sta->rate_ctrl_priv; | |
925 | } | |
926 | ||
35c347ac JB |
927 | if (ista) { |
928 | spin_lock_bh(&sta->rate_ctrl_lock); | |
929 | ref->ops->get_rate(ref->priv, ista, priv_sta, txrc); | |
930 | spin_unlock_bh(&sta->rate_ctrl_lock); | |
931 | } else { | |
1e87fec9 | 932 | rate_control_send_low(NULL, txrc); |
35c347ac | 933 | } |
e6a9854b | 934 | |
30686bf7 | 935 | if (ieee80211_hw_check(&sdata->local->hw, SUPPORTS_RC_TABLE)) |
0d528d85 FF |
936 | return; |
937 | ||
938 | ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb, | |
939 | info->control.rates, | |
940 | ARRAY_SIZE(info->control.rates)); | |
941 | } | |
e6a9854b | 942 | |
0d528d85 FF |
943 | int rate_control_set_rates(struct ieee80211_hw *hw, |
944 | struct ieee80211_sta *pubsta, | |
945 | struct ieee80211_sta_rates *rates) | |
946 | { | |
f815e2b3 | 947 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
f6b3d85f | 948 | struct ieee80211_sta_rates *old; |
e910867b | 949 | struct ieee80211_supported_band *sband; |
0d528d85 | 950 | |
21a8e9dd MSS |
951 | sband = ieee80211_get_sband(sta->sdata); |
952 | if (!sband) | |
953 | return -EINVAL; | |
e910867b | 954 | rate_control_apply_mask_ratetbl(sta, sband, rates); |
f6b3d85f FF |
955 | /* |
956 | * mac80211 guarantees that this function will not be called | |
957 | * concurrently, so the following RCU access is safe, even without | |
958 | * extra locking. This can not be checked easily, so we just set | |
959 | * the condition to true. | |
960 | */ | |
961 | old = rcu_dereference_protected(pubsta->rates, true); | |
0d528d85 FF |
962 | rcu_assign_pointer(pubsta->rates, rates); |
963 | if (old) | |
964 | kfree_rcu(old, rcu_head); | |
965 | ||
18fe0fae FF |
966 | if (sta->uploaded) |
967 | drv_sta_rate_tbl_update(hw_to_local(hw), sta->sdata, pubsta); | |
f815e2b3 | 968 | |
484a54c2 THJ |
969 | ieee80211_sta_set_expected_throughput(pubsta, sta_get_expected_throughput(sta)); |
970 | ||
0d528d85 | 971 | return 0; |
1abbe498 | 972 | } |
0d528d85 | 973 | EXPORT_SYMBOL(rate_control_set_rates); |
1abbe498 | 974 | |
ff688089 JB |
975 | int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, |
976 | const char *name) | |
977 | { | |
889cbb91 | 978 | struct rate_control_ref *ref; |
ff688089 JB |
979 | |
980 | ASSERT_RTNL(); | |
af65cd96 | 981 | |
3b8d81e0 | 982 | if (local->open_count) |
ff688089 JB |
983 | return -EBUSY; |
984 | ||
30686bf7 | 985 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
af65cd96 JB |
986 | if (WARN_ON(!local->ops->set_rts_threshold)) |
987 | return -EINVAL; | |
988 | return 0; | |
989 | } | |
990 | ||
ff688089 JB |
991 | ref = rate_control_alloc(name, local); |
992 | if (!ref) { | |
0fb9a9ec JP |
993 | wiphy_warn(local->hw.wiphy, |
994 | "Failed to select rate control algorithm\n"); | |
ff688089 JB |
995 | return -ENOENT; |
996 | } | |
997 | ||
889cbb91 | 998 | WARN_ON(local->rate_ctrl); |
ff688089 | 999 | local->rate_ctrl = ref; |
ff688089 | 1000 | |
0fb9a9ec JP |
1001 | wiphy_debug(local->hw.wiphy, "Selected rate control algorithm '%s'\n", |
1002 | ref->ops->name); | |
ff688089 | 1003 | |
ff688089 JB |
1004 | return 0; |
1005 | } | |
1006 | ||
1007 | void rate_control_deinitialize(struct ieee80211_local *local) | |
1008 | { | |
1009 | struct rate_control_ref *ref; | |
1010 | ||
1011 | ref = local->rate_ctrl; | |
af65cd96 JB |
1012 | |
1013 | if (!ref) | |
1014 | return; | |
1015 | ||
ff688089 | 1016 | local->rate_ctrl = NULL; |
a858958b | 1017 | rate_control_free(local, ref); |
ff688089 | 1018 | } |