Lines Matching +full:fixed +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()
207 KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode)); in ath_rate_update()
210 "%s: set xmit rate to %dM", __func__, in ath_rate_update()
211 ni->ni_rates.rs_nrates > 0 ? in ath_rate_update()
212 (ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL) / 2 : 0); in ath_rate_update()
215 * Before associating a node has no rate set setup in ath_rate_update()
219 * lowest hardware rate. in ath_rate_update()
221 if (ni->ni_rates.rs_nrates == 0) in ath_rate_update()
223 on->on_rix = rate; in ath_rate_update()
224 ni->ni_txrate = ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL; in ath_rate_update()
225 on->on_tx_rix0 = sc->sc_rixmap[ni->ni_txrate]; in ath_rate_update()
226 on->on_tx_rate0 = rt->info[on->on_tx_rix0].rateCode; in ath_rate_update()
228 on->on_tx_rate0sp = on->on_tx_rate0 | in ath_rate_update()
229 rt->info[on->on_tx_rix0].shortPreamble; in ath_rate_update()
230 if (sc->sc_mrretry) { in ath_rate_update()
232 * Hardware supports multi-rate retry; setup two in ath_rate_update()
233 * step-down retry rates and make the lowest rate in ath_rate_update()
235 * respectively (4 is set here, the rest are fixed in ath_rate_update()
238 on->on_tx_try0 = 1 + 3; /* 4 tries at rate 0 */ in ath_rate_update()
239 if (--rate >= 0) { in ath_rate_update()
240 rix = sc->sc_rixmap[ in ath_rate_update()
241 ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; in ath_rate_update()
242 on->on_tx_rate1 = rt->info[rix].rateCode; in ath_rate_update()
243 on->on_tx_rate1sp = on->on_tx_rate1 | in ath_rate_update()
244 rt->info[rix].shortPreamble; in ath_rate_update()
246 on->on_tx_rate1 = on->on_tx_rate1sp = 0; in ath_rate_update()
248 if (--rate >= 0) { in ath_rate_update()
249 rix = sc->sc_rixmap[ in ath_rate_update()
250 ni->ni_rates.rs_rates[rate]&IEEE80211_RATE_VAL]; in ath_rate_update()
251 on->on_tx_rate2 = rt->info[rix].rateCode; in ath_rate_update()
252 on->on_tx_rate2sp = on->on_tx_rate2 | in ath_rate_update()
253 rt->info[rix].shortPreamble; in ath_rate_update()
255 on->on_tx_rate2 = on->on_tx_rate2sp = 0; in ath_rate_update()
257 if (rate > 0) { in ath_rate_update()
259 on->on_tx_rate3 = rt->info[0].rateCode; in ath_rate_update()
260 on->on_tx_rate3sp = in ath_rate_update()
261 on->on_tx_rate3 | rt->info[0].shortPreamble; in ath_rate_update()
263 on->on_tx_rate3 = on->on_tx_rate3sp = 0; in ath_rate_update()
266 on->on_tx_try0 = ATH_TXMAXTRY; /* max tries at rate 0 */ in ath_rate_update()
267 on->on_tx_rate1 = on->on_tx_rate1sp = 0; in ath_rate_update()
268 on->on_tx_rate2 = on->on_tx_rate2sp = 0; in ath_rate_update()
269 on->on_tx_rate3 = on->on_tx_rate3sp = 0; in ath_rate_update()
272 on->on_tx_ok = on->on_tx_err = on->on_tx_retr = on->on_tx_upper = 0; in ath_rate_update()
274 on->on_interval = ath_rateinterval; in ath_rate_update()
275 if (vap->iv_opmode == IEEE80211_M_STA) in ath_rate_update()
276 on->on_interval /= 2; in ath_rate_update()
277 on->on_interval = (on->on_interval * hz) / 1000; in ath_rate_update()
281 * Set the starting transmit rate for a node.
286 #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL) in ath_rate_ctl_start() macro
287 const struct ieee80211_txparam *tp = ni->ni_txparms; in ath_rate_ctl_start()
290 KASSERT(ni->ni_rates.rs_nrates > 0, ("no rates")); in ath_rate_ctl_start()
291 if (tp == NULL || tp->ucastrate == IEEE80211_FIXED_RATE_NONE) { in ath_rate_ctl_start()
293 * No fixed rate is requested. For 11b start with in ath_rate_ctl_start()
294 * the highest negotiated rate; otherwise, for 11g in ath_rate_ctl_start()
297 srate = ni->ni_rates.rs_nrates - 1; in ath_rate_ctl_start()
298 if (sc->sc_curmode != IEEE80211_MODE_11B) { in ath_rate_ctl_start()
300 * Scan the negotiated rate set to find the in ath_rate_ctl_start()
301 * closest rate. in ath_rate_ctl_start()
303 /* NB: the rate set is assumed sorted */ in ath_rate_ctl_start()
304 for (; srate >= 0 && RATE(srate) > 72; srate--) in ath_rate_ctl_start()
309 * A fixed rate is to be used; ic_fixed_rate is the in ath_rate_ctl_start()
310 * IEEE code for this rate (sans basic bit). Convert this in ath_rate_ctl_start()
311 * to the index into the negotiated rate set for in ath_rate_ctl_start()
312 * the node. We know the rate is there because the in ath_rate_ctl_start()
313 * rate set is checked when the station associates. in ath_rate_ctl_start()
315 /* NB: the rate set is assumed sorted */ in ath_rate_ctl_start()
316 srate = ni->ni_rates.rs_nrates - 1; in ath_rate_ctl_start()
317 for (; srate >= 0 && RATE(srate) != tp->ucastrate; srate--) in ath_rate_ctl_start()
321 * The selected rate may not be available due to races in ath_rate_ctl_start()
323 * adhoc mode may not have any rate set so this lookup in ath_rate_ctl_start()
327 #undef RATE in ath_rate_ctl_start()
331 * Examine and potentially adjust the transmit rate.
338 struct ieee80211_rateset *rs = &ni->ni_rates; in ath_rate_ctl()
342 * Rate control in ath_rate_ctl()
345 enough = (on->on_tx_ok + on->on_tx_err >= 10); in ath_rate_ctl()
347 /* no packet reached -> down */ in ath_rate_ctl()
348 if (on->on_tx_err > 0 && on->on_tx_ok == 0) in ath_rate_ctl()
349 dir = -1; in ath_rate_ctl()
351 /* all packets needs retry in average -> down */ in ath_rate_ctl()
352 if (enough && on->on_tx_ok < on->on_tx_retr) in ath_rate_ctl()
353 dir = -1; in ath_rate_ctl()
355 /* no error and less than rate_raise% of packets need retry -> up */ in ath_rate_ctl()
356 if (enough && on->on_tx_err == 0 && in ath_rate_ctl()
357 on->on_tx_retr < (on->on_tx_ok * ath_rate_raise) / 100) in ath_rate_ctl()
360 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, in ath_rate_ctl()
362 on->on_tx_ok, on->on_tx_err, on->on_tx_retr, on->on_tx_upper, dir); in ath_rate_ctl()
364 nrate = on->on_rix; in ath_rate_ctl()
367 if (enough && on->on_tx_upper > 0) in ath_rate_ctl()
368 on->on_tx_upper--; in ath_rate_ctl()
370 case -1: in ath_rate_ctl()
372 nrate--; in ath_rate_ctl()
373 sc->sc_stats.ast_rate_drop++; in ath_rate_ctl()
375 on->on_tx_upper = 0; in ath_rate_ctl()
378 /* raise rate if we hit rate_raise_threshold */ in ath_rate_ctl()
379 if (++on->on_tx_upper < ath_rate_raise_threshold) in ath_rate_ctl()
381 on->on_tx_upper = 0; in ath_rate_ctl()
382 if (nrate + 1 < rs->rs_nrates) { in ath_rate_ctl()
384 sc->sc_stats.ast_rate_raise++; in ath_rate_ctl()
389 if (nrate != on->on_rix) { in ath_rate_ctl()
390 IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni, in ath_rate_ctl()
391 "%s: %dM -> %dM (%d ok, %d err, %d retr)", __func__, in ath_rate_ctl()
392 ni->ni_txrate / 2, in ath_rate_ctl()
393 (rs->rs_rates[nrate] & IEEE80211_RATE_VAL) / 2, in ath_rate_ctl()
394 on->on_tx_ok, on->on_tx_err, on->on_tx_retr); in ath_rate_ctl()
397 on->on_tx_ok = on->on_tx_err = on->on_tx_retr = 0; in ath_rate_ctl()
403 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); in ath_rate_sysctlattach()
404 struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); in ath_rate_sysctlattach()
408 "rate control: operation interval (ms)"); in ath_rate_sysctlattach()
412 "rate control: retry threshold to credit rate raise (%%)"); in ath_rate_sysctlattach()
415 "rate control: # good periods before raising rate"); in ath_rate_sysctlattach()
434 osc->arc.arc_space = sizeof(struct onoe_node); in ath_rate_attach()
437 return &osc->arc; in ath_rate_attach()