Lines Matching +full:convert +full:- +full:rate
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
5 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
18 * 3. Neither the names of the above-listed copyright holders nor the names
43 * AMRR rate control. See:
44 * http://www-sop.inria.fr/rapports/sophia/RR-5208.html
45 * "IEEE 802.11 Rate Adaptation: A Practical Approach" by
83 static int ath_rateinterval = 1000; /* rate ctl interval (ms) */
88 int rate);
111 *rix = amn->amn_tx_rix0; in ath_rate_findrate()
112 *try0 = amn->amn_tx_try0; in ath_rate_findrate()
114 *txrate = amn->amn_tx_rate0sp; in ath_rate_findrate()
116 *txrate = amn->amn_tx_rate0; in ath_rate_findrate()
117 maxdur = -1; in ath_rate_findrate()
118 maxpktlen = -1; in ath_rate_findrate()
125 * the returned rate with the relevant preamble rate flag.
135 rc[0].rix = amn->amn_tx_rate0; in ath_rate_getxtxrates()
136 rc[1].rix = amn->amn_tx_rate1; in ath_rate_getxtxrates()
137 rc[2].rix = amn->amn_tx_rate2; in ath_rate_getxtxrates()
138 rc[3].rix = amn->amn_tx_rate3; in ath_rate_getxtxrates()
140 rc[0].tries = amn->amn_tx_try0; in ath_rate_getxtxrates()
141 rc[1].tries = amn->amn_tx_try1; in ath_rate_getxtxrates()
142 rc[2].tries = amn->amn_tx_try2; in ath_rate_getxtxrates()
143 rc[3].tries = amn->amn_tx_try3; in ath_rate_getxtxrates()
152 ath_hal_setupxtxdesc(sc->sc_ah, ds in ath_rate_setupxtxdesc()
153 , amn->amn_tx_rate1sp, amn->amn_tx_try1 /* series 1 */ in ath_rate_setupxtxdesc()
154 , amn->amn_tx_rate2sp, amn->amn_tx_try2 /* series 2 */ in ath_rate_setupxtxdesc()
155 , amn->amn_tx_rate3sp, amn->amn_tx_try3 /* series 3 */ in ath_rate_setupxtxdesc()
165 int sr = ts->ts_shortretry; in ath_rate_tx_complete()
166 int lr = ts->ts_longretry; in ath_rate_tx_complete()
169 amn->amn_tx_try0_cnt++; in ath_rate_tx_complete()
171 amn->amn_tx_try1_cnt++; in ath_rate_tx_complete()
173 amn->amn_tx_try1_cnt++; in ath_rate_tx_complete()
174 amn->amn_tx_try2_cnt++; in ath_rate_tx_complete()
176 amn->amn_tx_try1_cnt++; in ath_rate_tx_complete()
177 amn->amn_tx_try2_cnt++; in ath_rate_tx_complete()
178 amn->amn_tx_try3_cnt++; in ath_rate_tx_complete()
180 amn->amn_tx_try1_cnt++; in ath_rate_tx_complete()
181 amn->amn_tx_try2_cnt++; in ath_rate_tx_complete()
182 amn->amn_tx_try3_cnt++; in ath_rate_tx_complete()
183 amn->amn_tx_failure_cnt++; in ath_rate_tx_complete()
185 if (amn->amn_interval != 0 && in ath_rate_tx_complete()
186 ticks - amn->amn_ticks > amn->amn_interval) { in ath_rate_tx_complete()
187 ath_rate_ctl(sc, &an->an_node); in ath_rate_tx_complete()
188 amn->amn_ticks = ticks; in ath_rate_tx_complete()
196 ath_rate_ctl_start(sc, &an->an_node); in ath_rate_newassoc()
207 amn->amn_tx_try0_cnt = 0; in node_reset()
208 amn->amn_tx_try1_cnt = 0; in node_reset()
209 amn->amn_tx_try2_cnt = 0; in node_reset()
210 amn->amn_tx_try3_cnt = 0; in node_reset()
211 amn->amn_tx_failure_cnt = 0; in node_reset()
212 amn->amn_success = 0; in node_reset()
213 amn->amn_recovery = 0; in node_reset()
214 amn->amn_success_threshold = ath_rate_min_success_threshold; in node_reset()
218 * The code below assumes that we are dealing with hardware multi rate retry
224 ath_rate_update(struct ath_softc *sc, struct ieee80211_node *ni, int rate) in ath_rate_update() argument
228 struct ieee80211vap *vap = ni->ni_vap; in ath_rate_update()
229 const HAL_RATE_TABLE *rt = sc->sc_currates; in ath_rate_update()
232 KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); in ath_rate_update()
235 "%s: set xmit rate to %dM", __func__, in ath_rate_update()
236 ni->ni_rates.rs_nrates > 0 ? in ath_rate_update()
237 (ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL) / 2 : 0); in ath_rate_update()
239 amn->amn_rix = rate; in ath_rate_update()
241 * Before associating a node has no rate set setup in ath_rate_update()
245 * lowest hardware rate. in ath_rate_update()
247 if (ni->ni_rates.rs_nrates > 0) { in ath_rate_update()
250 dot11rate = ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL; in ath_rate_update()
251 amn->amn_tx_rix0 = sc->sc_rixmap[dot11rate]; in ath_rate_update()
253 amn->amn_tx_rate0 = rt->info[amn->amn_tx_rix0].rateCode; in ath_rate_update()
254 amn->amn_tx_rate0sp = amn->amn_tx_rate0 | in ath_rate_update()
255 rt->info[amn->amn_tx_rix0].shortPreamble; in ath_rate_update()
256 if (sc->sc_mrretry) { in ath_rate_update()
257 amn->amn_tx_try0 = 1; in ath_rate_update()
258 amn->amn_tx_try1 = 1; in ath_rate_update()
259 amn->amn_tx_try2 = 1; in ath_rate_update()
260 amn->amn_tx_try3 = 1; in ath_rate_update()
261 if (--rate >= 0) { in ath_rate_update()
262 rix = sc->sc_rixmap[ in ath_rate_update()
263 ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; in ath_rate_update()
264 amn->amn_tx_rate1 = rt->info[rix].rateCode; in ath_rate_update()
265 amn->amn_tx_rate1sp = amn->amn_tx_rate1 | in ath_rate_update()
266 rt->info[rix].shortPreamble; in ath_rate_update()
268 amn->amn_tx_rate1 = amn->amn_tx_rate1sp = 0; in ath_rate_update()
270 if (--rate >= 0) { in ath_rate_update()
271 rix = sc->sc_rixmap[ in ath_rate_update()
272 ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; in ath_rate_update()
273 amn->amn_tx_rate2 = rt->info[rix].rateCode; in ath_rate_update()
274 amn->amn_tx_rate2sp = amn->amn_tx_rate2 | in ath_rate_update()
275 rt->info[rix].shortPreamble; in ath_rate_update()
277 amn->amn_tx_rate2 = amn->amn_tx_rate2sp = 0; in ath_rate_update()
279 if (rate > 0) { in ath_rate_update()
281 amn->amn_tx_rate3 = rt->info[0].rateCode; in ath_rate_update()
282 amn->amn_tx_rate3sp = in ath_rate_update()
283 amn->amn_tx_rate3 | rt->info[0].shortPreamble; in ath_rate_update()
285 amn->amn_tx_rate3 = amn->amn_tx_rate3sp = 0; in ath_rate_update()
288 amn->amn_tx_try0 = ATH_TXMAXTRY; in ath_rate_update()
292 amn->amn_tx_try1 = 0; in ath_rate_update()
293 amn->amn_tx_try2 = 0; in ath_rate_update()
294 amn->amn_tx_try3 = 0; in ath_rate_update()
295 amn->amn_tx_rate1 = amn->amn_tx_rate1sp = 0; in ath_rate_update()
296 amn->amn_tx_rate2 = amn->amn_tx_rate2sp = 0; in ath_rate_update()
297 amn->amn_tx_rate3 = amn->amn_tx_rate3sp = 0; in ath_rate_update()
302 amn->amn_interval = ath_rateinterval; in ath_rate_update()
303 if (vap->iv_opmode == IEEE80211_M_STA) in ath_rate_update()
304 amn->amn_interval /= 2; in ath_rate_update()
305 amn->amn_interval = (amn->amn_interval * hz) / 1000; in ath_rate_update()
309 * Set the starting transmit rate for a node.
314 #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL) in ath_rate_ctl_start() macro
315 const struct ieee80211_txparam *tp = ni->ni_txparms; in ath_rate_ctl_start()
318 KASSERT(ni->ni_rates.rs_nrates > 0, ("no rates")); in ath_rate_ctl_start()
319 if (tp == NULL || tp->ucastrate == IEEE80211_FIXED_RATE_NONE) { in ath_rate_ctl_start()
321 * No fixed rate is requested. For 11b start with in ath_rate_ctl_start()
322 * the highest negotiated rate; otherwise, for 11g in ath_rate_ctl_start()
325 srate = ni->ni_rates.rs_nrates - 1; in ath_rate_ctl_start()
326 if (sc->sc_curmode != IEEE80211_MODE_11B) { in ath_rate_ctl_start()
328 * Scan the negotiated rate set to find the in ath_rate_ctl_start()
329 * closest rate. in ath_rate_ctl_start()
331 /* NB: the rate set is assumed sorted */ in ath_rate_ctl_start()
332 for (; srate >= 0 && RATE(srate) > 72; srate--) in ath_rate_ctl_start()
337 * A fixed rate is to be used; ic_fixed_rate is the in ath_rate_ctl_start()
338 * IEEE code for this rate (sans basic bit). Convert this in ath_rate_ctl_start()
339 * to the index into the negotiated rate set for in ath_rate_ctl_start()
340 * the node. We know the rate is there because the in ath_rate_ctl_start()
341 * rate set is checked when the station associates. in ath_rate_ctl_start()
343 /* NB: the rate set is assumed sorted */ in ath_rate_ctl_start()
344 srate = ni->ni_rates.rs_nrates - 1; in ath_rate_ctl_start()
345 for (; srate >= 0 && RATE(srate) != tp->ucastrate; srate--) in ath_rate_ctl_start()
349 * The selected rate may not be available due to races in ath_rate_ctl_start()
351 * adhoc mode may not have any rate set so this lookup in ath_rate_ctl_start()
355 #undef RATE in ath_rate_ctl_start()
359 * Examine and potentially adjust the transmit rate.
369 (amn->amn_tx_try1_cnt < (amn->amn_tx_try0_cnt/10)) in ath_rate_ctl()
371 (amn->amn_tx_try0_cnt > 10) in ath_rate_ctl()
373 (amn->amn_tx_try1_cnt > (amn->amn_tx_try0_cnt/3)) in ath_rate_ctl()
375 rix = amn->amn_rix; in ath_rate_ctl()
377 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, in ath_rate_ctl()
378 "cnt0: %d cnt1: %d cnt2: %d cnt3: %d -- threshold: %d", in ath_rate_ctl()
379 amn->amn_tx_try0_cnt, amn->amn_tx_try1_cnt, amn->amn_tx_try2_cnt, in ath_rate_ctl()
380 amn->amn_tx_try3_cnt, amn->amn_success_threshold); in ath_rate_ctl()
382 amn->amn_success++; in ath_rate_ctl()
383 if (amn->amn_success == amn->amn_success_threshold && in ath_rate_ctl()
384 rix + 1 < ni->ni_rates.rs_nrates) { in ath_rate_ctl()
385 amn->amn_recovery = 1; in ath_rate_ctl()
386 amn->amn_success = 0; in ath_rate_ctl()
388 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, in ath_rate_ctl()
389 "increase rate to %d", rix); in ath_rate_ctl()
391 amn->amn_recovery = 0; in ath_rate_ctl()
394 amn->amn_success = 0; in ath_rate_ctl()
396 if (amn->amn_recovery) { in ath_rate_ctl()
398 amn->amn_success_threshold *= 2; in ath_rate_ctl()
399 amn->amn_success_threshold = min (amn->amn_success_threshold, in ath_rate_ctl()
401 IEEE80211_NOTE(ni->ni_vap, in ath_rate_ctl()
403 "decrease rate recovery thr: %d", in ath_rate_ctl()
404 amn->amn_success_threshold); in ath_rate_ctl()
407 amn->amn_success_threshold = ath_rate_min_success_threshold; in ath_rate_ctl()
408 IEEE80211_NOTE(ni->ni_vap, in ath_rate_ctl()
410 "decrease rate normal thr: %d", in ath_rate_ctl()
411 amn->amn_success_threshold); in ath_rate_ctl()
413 amn->amn_recovery = 0; in ath_rate_ctl()
414 rix--; in ath_rate_ctl()
416 amn->amn_recovery = 0; in ath_rate_ctl()
419 if (is_enough (amn) || rix != amn->amn_rix) { in ath_rate_ctl()
421 amn->amn_tx_try0_cnt = 0; in ath_rate_ctl()
422 amn->amn_tx_try1_cnt = 0; in ath_rate_ctl()
423 amn->amn_tx_try2_cnt = 0; in ath_rate_ctl()
424 amn->amn_tx_try3_cnt = 0; in ath_rate_ctl()
425 amn->amn_tx_failure_cnt = 0; in ath_rate_ctl()
427 if (rix != amn->amn_rix) { in ath_rate_ctl()
443 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); in ath_rate_sysctlattach()
444 struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); in ath_rate_sysctlattach()
448 "rate control: operation interval (ms)"); in ath_rate_sysctlattach()
466 asc->arc.arc_space = sizeof(struct amrr_node); in ath_rate_attach()
469 return &asc->arc; in ath_rate_attach()