Lines Matching +full:convert +full:- +full:rate

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2002-2007 Sam Leffler, Errno Consulting
34 * Atsushi Onoe's rate control algorithm.
73 * Default parameters for the rate control algorithm. These are
74 * all tunable with sysctls. The rate controller runs periodically
78 * it gives a "raise rate credit". If transmits look to not be working
80 * the transmit rate is raised. Various error conditions force the
81 * the transmit rate to be dropped.
87 * the transmit rate is increased.
91 static int ath_rateinterval = 1000; /* rate ctl interval (ms) */
93 static int ath_rate_raise_threshold = 10; /* rate ctl raise threshold */
96 int rate);
119 *rix = on->on_tx_rix0; in ath_rate_findrate()
120 *try0 = on->on_tx_try0; in ath_rate_findrate()
122 *txrate = on->on_tx_rate0sp; in ath_rate_findrate()
124 *txrate = on->on_tx_rate0; in ath_rate_findrate()
125 *maxdur = -1; in ath_rate_findrate()
126 *maxpktlen = -1; in ath_rate_findrate()
133 * the returned rate with the relevant preamble rate flag.
143 rc[0].rix = on->on_tx_rate0; in ath_rate_getxtxrates()
144 rc[1].rix = on->on_tx_rate1; in ath_rate_getxtxrates()
145 rc[2].rix = on->on_tx_rate2; in ath_rate_getxtxrates()
146 rc[3].rix = on->on_tx_rate3; in ath_rate_getxtxrates()
148 rc[0].tries = on->on_tx_try0; in ath_rate_getxtxrates()
160 ath_hal_setupxtxdesc(sc->sc_ah, ds in ath_rate_setupxtxdesc()
161 , on->on_tx_rate1sp, 2 /* series 1 */ in ath_rate_setupxtxdesc()
162 , on->on_tx_rate2sp, 2 /* series 2 */ in ath_rate_setupxtxdesc()
163 , on->on_tx_rate3sp, 2 /* series 3 */ in ath_rate_setupxtxdesc()
174 if (ts->ts_status == 0) in ath_rate_tx_complete()
175 on->on_tx_ok++; in ath_rate_tx_complete()
177 on->on_tx_err++; in ath_rate_tx_complete()
178 on->on_tx_retr += ts->ts_shortretry in ath_rate_tx_complete()
179 + ts->ts_longretry; in ath_rate_tx_complete()
180 if (on->on_interval != 0 && ticks - on->on_ticks > on->on_interval) { in ath_rate_tx_complete()
181 ath_rate_ctl(sc, &an->an_node); in ath_rate_tx_complete()
182 on->on_ticks = ticks; in ath_rate_tx_complete()
190 ath_rate_ctl_start(sc, &an->an_node); in ath_rate_newassoc()
199 ath_rate_update(struct ath_softc *sc, struct ieee80211_node *ni, int rate) in ath_rate_update() argument
203 struct ieee80211vap *vap = ni->ni_vap; in ath_rate_update()
204 const HAL_RATE_TABLE *rt = sc->sc_currates; in ath_rate_update()
208 KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); in ath_rate_update()
211 "%s: set xmit rate to %dM", __func__, in ath_rate_update()
212 ni->ni_rates.rs_nrates > 0 ? in ath_rate_update()
213 (ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL) / 2 : 0); in ath_rate_update()
216 * Before associating a node has no rate set setup in ath_rate_update()
220 * lowest hardware rate. in ath_rate_update()
222 if (ni->ni_rates.rs_nrates == 0) in ath_rate_update()
224 on->on_rix = rate; in ath_rate_update()
225 dot11rate = ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL; in ath_rate_update()
227 on->on_tx_rix0 = sc->sc_rixmap[dot11rate]; in ath_rate_update()
228 on->on_tx_rate0 = rt->info[on->on_tx_rix0].rateCode; in ath_rate_update()
230 on->on_tx_rate0sp = on->on_tx_rate0 | in ath_rate_update()
231 rt->info[on->on_tx_rix0].shortPreamble; in ath_rate_update()
232 if (sc->sc_mrretry) { in ath_rate_update()
234 * Hardware supports multi-rate retry; setup two in ath_rate_update()
235 * step-down retry rates and make the lowest rate in ath_rate_update()
240 on->on_tx_try0 = 1 + 3; /* 4 tries at rate 0 */ in ath_rate_update()
241 if (--rate >= 0) { in ath_rate_update()
242 rix = sc->sc_rixmap[ in ath_rate_update()
243 ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; in ath_rate_update()
244 on->on_tx_rate1 = rt->info[rix].rateCode; in ath_rate_update()
245 on->on_tx_rate1sp = on->on_tx_rate1 | in ath_rate_update()
246 rt->info[rix].shortPreamble; in ath_rate_update()
248 on->on_tx_rate1 = on->on_tx_rate1sp = 0; in ath_rate_update()
250 if (--rate >= 0) { in ath_rate_update()
251 rix = sc->sc_rixmap[ in ath_rate_update()
252 ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; in ath_rate_update()
253 on->on_tx_rate2 = rt->info[rix].rateCode; in ath_rate_update()
254 on->on_tx_rate2sp = on->on_tx_rate2 | in ath_rate_update()
255 rt->info[rix].shortPreamble; in ath_rate_update()
257 on->on_tx_rate2 = on->on_tx_rate2sp = 0; in ath_rate_update()
259 if (rate > 0) { in ath_rate_update()
261 on->on_tx_rate3 = rt->info[0].rateCode; in ath_rate_update()
262 on->on_tx_rate3sp = in ath_rate_update()
263 on->on_tx_rate3 | rt->info[0].shortPreamble; in ath_rate_update()
265 on->on_tx_rate3 = on->on_tx_rate3sp = 0; in ath_rate_update()
268 on->on_tx_try0 = ATH_TXMAXTRY; /* max tries at rate 0 */ in ath_rate_update()
269 on->on_tx_rate1 = on->on_tx_rate1sp = 0; in ath_rate_update()
270 on->on_tx_rate2 = on->on_tx_rate2sp = 0; in ath_rate_update()
271 on->on_tx_rate3 = on->on_tx_rate3sp = 0; in ath_rate_update()
274 on->on_tx_ok = on->on_tx_err = on->on_tx_retr = on->on_tx_upper = 0; in ath_rate_update()
276 on->on_interval = ath_rateinterval; in ath_rate_update()
277 if (vap->iv_opmode == IEEE80211_M_STA) in ath_rate_update()
278 on->on_interval /= 2; in ath_rate_update()
279 on->on_interval = (on->on_interval * hz) / 1000; in ath_rate_update()
283 * Set the starting transmit rate for a node.
288 #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL) in ath_rate_ctl_start() macro
289 const struct ieee80211_txparam *tp = ni->ni_txparms; in ath_rate_ctl_start()
292 KASSERT(ni->ni_rates.rs_nrates > 0, ("no rates")); in ath_rate_ctl_start()
293 if (tp == NULL || tp->ucastrate == IEEE80211_FIXED_RATE_NONE) { in ath_rate_ctl_start()
295 * No fixed rate is requested. For 11b start with in ath_rate_ctl_start()
296 * the highest negotiated rate; otherwise, for 11g in ath_rate_ctl_start()
299 srate = ni->ni_rates.rs_nrates - 1; in ath_rate_ctl_start()
300 if (sc->sc_curmode != IEEE80211_MODE_11B) { in ath_rate_ctl_start()
302 * Scan the negotiated rate set to find the in ath_rate_ctl_start()
303 * closest rate. in ath_rate_ctl_start()
305 /* NB: the rate set is assumed sorted */ in ath_rate_ctl_start()
306 for (; srate >= 0 && RATE(srate) > 72; srate--) in ath_rate_ctl_start()
311 * A fixed rate is to be used; ic_fixed_rate is the in ath_rate_ctl_start()
312 * IEEE code for this rate (sans basic bit). Convert this in ath_rate_ctl_start()
313 * to the index into the negotiated rate set for in ath_rate_ctl_start()
314 * the node. We know the rate is there because the in ath_rate_ctl_start()
315 * rate set is checked when the station associates. in ath_rate_ctl_start()
317 /* NB: the rate set is assumed sorted */ in ath_rate_ctl_start()
318 srate = ni->ni_rates.rs_nrates - 1; in ath_rate_ctl_start()
319 for (; srate >= 0 && RATE(srate) != tp->ucastrate; srate--) in ath_rate_ctl_start()
323 * The selected rate may not be available due to races in ath_rate_ctl_start()
325 * adhoc mode may not have any rate set so this lookup in ath_rate_ctl_start()
329 #undef RATE in ath_rate_ctl_start()
333 * Examine and potentially adjust the transmit rate.
340 struct ieee80211_rateset *rs = &ni->ni_rates; in ath_rate_ctl()
344 * Rate control in ath_rate_ctl()
347 enough = (on->on_tx_ok + on->on_tx_err >= 10); in ath_rate_ctl()
349 /* no packet reached -> down */ in ath_rate_ctl()
350 if (on->on_tx_err > 0 && on->on_tx_ok == 0) in ath_rate_ctl()
351 dir = -1; in ath_rate_ctl()
353 /* all packets needs retry in average -> down */ in ath_rate_ctl()
354 if (enough && on->on_tx_ok < on->on_tx_retr) in ath_rate_ctl()
355 dir = -1; in ath_rate_ctl()
357 /* no error and less than rate_raise% of packets need retry -> up */ in ath_rate_ctl()
358 if (enough && on->on_tx_err == 0 && in ath_rate_ctl()
359 on->on_tx_retr < (on->on_tx_ok * ath_rate_raise) / 100) in ath_rate_ctl()
362 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, in ath_rate_ctl()
364 on->on_tx_ok, on->on_tx_err, on->on_tx_retr, on->on_tx_upper, dir); in ath_rate_ctl()
366 nrate = on->on_rix; in ath_rate_ctl()
369 if (enough && on->on_tx_upper > 0) in ath_rate_ctl()
370 on->on_tx_upper--; in ath_rate_ctl()
372 case -1: in ath_rate_ctl()
374 nrate--; in ath_rate_ctl()
375 sc->sc_stats.ast_rate_drop++; in ath_rate_ctl()
377 on->on_tx_upper = 0; in ath_rate_ctl()
380 /* raise rate if we hit rate_raise_threshold */ in ath_rate_ctl()
381 if (++on->on_tx_upper < ath_rate_raise_threshold) in ath_rate_ctl()
383 on->on_tx_upper = 0; in ath_rate_ctl()
384 if (nrate + 1 < rs->rs_nrates) { in ath_rate_ctl()
386 sc->sc_stats.ast_rate_raise++; in ath_rate_ctl()
391 if (nrate != on->on_rix) { in ath_rate_ctl()
392 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, in ath_rate_ctl()
393 "%s: %dM -> %dM (%d ok, %d err, %d retr)", __func__, in ath_rate_ctl()
395 (rs->rs_rates[nrate] & IEEE80211_RATE_VAL) / 2, in ath_rate_ctl()
396 on->on_tx_ok, on->on_tx_err, on->on_tx_retr); in ath_rate_ctl()
399 on->on_tx_ok = on->on_tx_err = on->on_tx_retr = 0; in ath_rate_ctl()
405 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); in ath_rate_sysctlattach()
406 struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); in ath_rate_sysctlattach()
410 "rate control: operation interval (ms)"); in ath_rate_sysctlattach()
414 "rate control: retry threshold to credit rate raise (%%)"); in ath_rate_sysctlattach()
417 "rate control: # good periods before raising rate"); in ath_rate_sysctlattach()
436 osc->arc.arc_space = sizeof(struct onoe_node); in ath_rate_attach()
439 return &osc->arc; in ath_rate_attach()