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