ieee80211_amrr.c revision 1.3.18.5 1 1.3.18.5 christos /* $NetBSD: ieee80211_amrr.c,v 1.3.18.5 2019/06/10 22:09:46 christos Exp $ */
2 1.3.18.2 phil
3 1.1 joerg /* $OpenBSD: ieee80211_amrr.c,v 1.1 2006/06/17 19:07:19 damien Exp $ */
4 1.1 joerg
5 1.1 joerg /*-
6 1.3.18.1 phil * Copyright (c) 2010 Rui Paulo <rpaulo (at) FreeBSD.org>
7 1.1 joerg * Copyright (c) 2006
8 1.1 joerg * Damien Bergamini <damien.bergamini (at) free.fr>
9 1.1 joerg *
10 1.1 joerg * Permission to use, copy, modify, and distribute this software for any
11 1.1 joerg * purpose with or without fee is hereby granted, provided that the above
12 1.1 joerg * copyright notice and this permission notice appear in all copies.
13 1.1 joerg *
14 1.1 joerg * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 1.1 joerg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 1.1 joerg * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 1.1 joerg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 1.1 joerg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 1.1 joerg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 1.1 joerg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 1.1 joerg */
22 1.1 joerg
23 1.2 lukem #include <sys/cdefs.h>
24 1.3.18.5 christos #ifdef __NetBSD__
25 1.3.18.5 christos __KERNEL_RCSID(0, "$NetBSD: ieee80211_amrr.c,v 1.3.18.5 2019/06/10 22:09:46 christos Exp $");
26 1.3.18.2 phil #endif
27 1.3 pooka
28 1.3.18.1 phil /*-
29 1.3.18.1 phil * Naive implementation of the Adaptive Multi Rate Retry algorithm:
30 1.3.18.1 phil *
31 1.3.18.1 phil * "IEEE 802.11 Rate Adaptation: A Practical Approach"
32 1.3.18.1 phil * Mathieu Lacage, Hossein Manshaei, Thierry Turletti
33 1.3.18.1 phil * INRIA Sophia - Projet Planete
34 1.3.18.1 phil * http://www-sop.inria.fr/rapports/sophia/RR-5208.html
35 1.3.18.1 phil */
36 1.3.18.5 christos #ifdef _KERNEL_OPT
37 1.3.18.1 phil #include "opt_wlan.h"
38 1.3.18.5 christos #endif
39 1.2 lukem
40 1.1 joerg #include <sys/param.h>
41 1.1 joerg #include <sys/kernel.h>
42 1.3.18.1 phil #include <sys/malloc.h>
43 1.3.18.1 phil #include <sys/module.h>
44 1.3.18.1 phil #include <sys/sbuf.h>
45 1.1 joerg #include <sys/socket.h>
46 1.1 joerg #include <sys/sysctl.h>
47 1.1 joerg
48 1.1 joerg #include <net/if.h>
49 1.3.18.2 phil #ifdef __FreeBSD__
50 1.3.18.1 phil #include <net/if_var.h>
51 1.3.18.2 phil #endif
52 1.1 joerg #include <net/if_media.h>
53 1.3.18.2 phil #ifdef __FreeBSD__
54 1.3.18.1 phil #include <net/ethernet.h>
55 1.3.18.2 phil #endif
56 1.3.18.2 phil #ifdef __NetBSD__
57 1.3.18.2 phil #include <net/route.h>
58 1.3.18.2 phil #endif
59 1.1 joerg
60 1.1 joerg #ifdef INET
61 1.1 joerg #include <netinet/in.h>
62 1.3.18.5 christos #ifdef __FreeBSD__
63 1.3.18.1 phil #include <netinet/if_ether.h>
64 1.1 joerg #endif
65 1.3.18.5 christos #endif
66 1.1 joerg
67 1.1 joerg #include <net80211/ieee80211_var.h>
68 1.3.18.1 phil #include <net80211/ieee80211_ht.h>
69 1.1 joerg #include <net80211/ieee80211_amrr.h>
70 1.3.18.1 phil #include <net80211/ieee80211_ratectl.h>
71 1.1 joerg
72 1.3.18.2 phil #ifdef __NetBSD__
73 1.3.18.2 phil #undef KASSERT
74 1.3.18.2 phil #define KASSERT(__cond, __complaint) FBSDKASSERT(__cond, __complaint)
75 1.3.18.2 phil #endif
76 1.3.18.2 phil
77 1.1 joerg #define is_success(amn) \
78 1.1 joerg ((amn)->amn_retrycnt < (amn)->amn_txcnt / 10)
79 1.1 joerg #define is_failure(amn) \
80 1.1 joerg ((amn)->amn_retrycnt > (amn)->amn_txcnt / 3)
81 1.1 joerg #define is_enough(amn) \
82 1.1 joerg ((amn)->amn_txcnt > 10)
83 1.3.18.1 phil
84 1.3.18.1 phil static void amrr_setinterval(const struct ieee80211vap *, int);
85 1.3.18.1 phil static void amrr_init(struct ieee80211vap *);
86 1.3.18.1 phil static void amrr_deinit(struct ieee80211vap *);
87 1.3.18.1 phil static void amrr_node_init(struct ieee80211_node *);
88 1.3.18.1 phil static void amrr_node_deinit(struct ieee80211_node *);
89 1.3.18.1 phil static int amrr_update(struct ieee80211_amrr *,
90 1.3.18.1 phil struct ieee80211_amrr_node *, struct ieee80211_node *);
91 1.3.18.1 phil static int amrr_rate(struct ieee80211_node *, void *, uint32_t);
92 1.3.18.1 phil static void amrr_tx_complete(const struct ieee80211_node *,
93 1.3.18.1 phil const struct ieee80211_ratectl_tx_status *);
94 1.3.18.1 phil static void amrr_tx_update_cb(void *, struct ieee80211_node *);
95 1.3.18.1 phil static void amrr_tx_update(struct ieee80211vap *vap,
96 1.3.18.1 phil struct ieee80211_ratectl_tx_stats *);
97 1.3.18.4 phil #ifdef notyet
98 1.3.18.1 phil static void amrr_sysctlattach(struct ieee80211vap *,
99 1.3.18.1 phil struct sysctl_ctx_list *, struct sysctl_oid *);
100 1.3.18.4 phil #endif
101 1.3.18.1 phil static void amrr_node_stats(struct ieee80211_node *ni, struct sbuf *s);
102 1.3.18.1 phil
103 1.3.18.1 phil /* number of references from net80211 layer */
104 1.3.18.1 phil static int nrefs = 0;
105 1.3.18.1 phil
106 1.3.18.3 phil #if __FreeBSD__
107 1.3.18.1 phil static const struct ieee80211_ratectl amrr = {
108 1.3.18.2 phil #else
109 1.3.18.3 phil const struct ieee80211_ratectl ratectl_amrr = {
110 1.3.18.2 phil #endif
111 1.3.18.1 phil .ir_name = "amrr",
112 1.3.18.1 phil .ir_attach = NULL,
113 1.3.18.1 phil .ir_detach = NULL,
114 1.3.18.1 phil .ir_init = amrr_init,
115 1.3.18.1 phil .ir_deinit = amrr_deinit,
116 1.3.18.1 phil .ir_node_init = amrr_node_init,
117 1.3.18.1 phil .ir_node_deinit = amrr_node_deinit,
118 1.3.18.1 phil .ir_rate = amrr_rate,
119 1.3.18.1 phil .ir_tx_complete = amrr_tx_complete,
120 1.3.18.1 phil .ir_tx_update = amrr_tx_update,
121 1.3.18.1 phil .ir_setinterval = amrr_setinterval,
122 1.3.18.1 phil .ir_node_stats = amrr_node_stats,
123 1.3.18.1 phil };
124 1.3.18.3 phil #if __FreeBSD__
125 1.3.18.1 phil IEEE80211_RATECTL_MODULE(amrr, 1);
126 1.3.18.1 phil IEEE80211_RATECTL_ALG(amrr, IEEE80211_RATECTL_AMRR, amrr);
127 1.3.18.2 phil #endif
128 1.3.18.2 phil
129 1.3.18.1 phil static void
130 1.3.18.1 phil amrr_setinterval(const struct ieee80211vap *vap, int msecs)
131 1.3.18.1 phil {
132 1.3.18.1 phil struct ieee80211_amrr *amrr = vap->iv_rs;
133 1.3.18.1 phil int t;
134 1.3.18.1 phil
135 1.3.18.1 phil if (msecs < 100)
136 1.3.18.1 phil msecs = 100;
137 1.3.18.1 phil t = msecs_to_ticks(msecs);
138 1.3.18.1 phil amrr->amrr_interval = (t < 1) ? 1 : t;
139 1.3.18.1 phil }
140 1.3.18.1 phil
141 1.3.18.1 phil static void
142 1.3.18.1 phil amrr_init(struct ieee80211vap *vap)
143 1.3.18.1 phil {
144 1.3.18.1 phil struct ieee80211_amrr *amrr;
145 1.3.18.1 phil
146 1.3.18.1 phil KASSERT(vap->iv_rs == NULL, ("%s called multiple times", __func__));
147 1.3.18.1 phil
148 1.3.18.1 phil nrefs++; /* XXX locking */
149 1.3.18.1 phil amrr = vap->iv_rs = IEEE80211_MALLOC(sizeof(struct ieee80211_amrr),
150 1.3.18.1 phil M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
151 1.3.18.1 phil if (amrr == NULL) {
152 1.3.18.1 phil if_printf(vap->iv_ifp, "couldn't alloc ratectl structure\n");
153 1.3.18.1 phil return;
154 1.3.18.1 phil }
155 1.3.18.1 phil amrr->amrr_min_success_threshold = IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD;
156 1.3.18.1 phil amrr->amrr_max_success_threshold = IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD;
157 1.3.18.1 phil amrr_setinterval(vap, 500 /* ms */);
158 1.3.18.4 phil #ifdef notyet
159 1.3.18.1 phil amrr_sysctlattach(vap, vap->iv_sysctl, vap->iv_oid);
160 1.3.18.4 phil #endif
161 1.3.18.1 phil }
162 1.3.18.1 phil
163 1.3.18.1 phil static void
164 1.3.18.1 phil amrr_deinit(struct ieee80211vap *vap)
165 1.3.18.1 phil {
166 1.3.18.1 phil IEEE80211_FREE(vap->iv_rs, M_80211_RATECTL);
167 1.3.18.1 phil KASSERT(nrefs > 0, ("imbalanced attach/detach"));
168 1.3.18.1 phil nrefs--; /* XXX locking */
169 1.3.18.1 phil }
170 1.3.18.1 phil
171 1.3.18.1 phil /*
172 1.3.18.1 phil * Return whether 11n rates are possible.
173 1.3.18.1 phil *
174 1.3.18.1 phil * Some 11n devices may return HT information but no HT rates.
175 1.3.18.1 phil * Thus, we shouldn't treat them as an 11n node.
176 1.3.18.1 phil */
177 1.3.18.1 phil static int
178 1.3.18.1 phil amrr_node_is_11n(struct ieee80211_node *ni)
179 1.3.18.1 phil {
180 1.3.18.1 phil
181 1.3.18.1 phil if (ni->ni_chan == NULL)
182 1.3.18.1 phil return (0);
183 1.3.18.1 phil if (ni->ni_chan == IEEE80211_CHAN_ANYC)
184 1.3.18.1 phil return (0);
185 1.3.18.1 phil if (IEEE80211_IS_CHAN_HT(ni->ni_chan) && ni->ni_htrates.rs_nrates == 0)
186 1.3.18.1 phil return (0);
187 1.3.18.1 phil return (IEEE80211_IS_CHAN_HT(ni->ni_chan));
188 1.3.18.1 phil }
189 1.3.18.1 phil
190 1.3.18.1 phil static void
191 1.3.18.1 phil amrr_node_init(struct ieee80211_node *ni)
192 1.1 joerg {
193 1.3.18.1 phil const struct ieee80211_rateset *rs = NULL;
194 1.3.18.1 phil struct ieee80211vap *vap = ni->ni_vap;
195 1.3.18.1 phil struct ieee80211_amrr *amrr = vap->iv_rs;
196 1.3.18.1 phil struct ieee80211_amrr_node *amn;
197 1.3.18.1 phil uint8_t rate;
198 1.3.18.1 phil
199 1.3.18.1 phil if (ni->ni_rctls == NULL) {
200 1.3.18.1 phil ni->ni_rctls = amn = IEEE80211_MALLOC(sizeof(struct ieee80211_amrr_node),
201 1.3.18.1 phil M_80211_RATECTL, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
202 1.3.18.1 phil if (amn == NULL) {
203 1.3.18.1 phil if_printf(vap->iv_ifp, "couldn't alloc per-node ratectl "
204 1.3.18.1 phil "structure\n");
205 1.3.18.1 phil return;
206 1.3.18.1 phil }
207 1.3.18.1 phil } else
208 1.3.18.1 phil amn = ni->ni_rctls;
209 1.3.18.1 phil amn->amn_amrr = amrr;
210 1.1 joerg amn->amn_success = 0;
211 1.1 joerg amn->amn_recovery = 0;
212 1.1 joerg amn->amn_txcnt = amn->amn_retrycnt = 0;
213 1.1 joerg amn->amn_success_threshold = amrr->amrr_min_success_threshold;
214 1.3.18.1 phil
215 1.3.18.1 phil /* 11n or not? Pick the right rateset */
216 1.3.18.1 phil if (amrr_node_is_11n(ni)) {
217 1.3.18.1 phil /* XXX ew */
218 1.3.18.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
219 1.3.18.1 phil "%s: 11n node", __func__);
220 1.3.18.1 phil rs = (struct ieee80211_rateset *) &ni->ni_htrates;
221 1.3.18.1 phil } else {
222 1.3.18.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
223 1.3.18.1 phil "%s: non-11n node", __func__);
224 1.3.18.1 phil rs = &ni->ni_rates;
225 1.3.18.1 phil }
226 1.3.18.1 phil
227 1.3.18.1 phil /* Initial rate - lowest */
228 1.3.18.1 phil rate = rs->rs_rates[0];
229 1.3.18.1 phil
230 1.3.18.1 phil /* XXX clear the basic rate flag if it's not 11n */
231 1.3.18.1 phil if (! amrr_node_is_11n(ni))
232 1.3.18.1 phil rate &= IEEE80211_RATE_VAL;
233 1.3.18.1 phil
234 1.3.18.1 phil /* pick initial rate from the rateset - HT or otherwise */
235 1.3.18.1 phil /* Pick something low that's likely to succeed */
236 1.3.18.1 phil for (amn->amn_rix = rs->rs_nrates - 1; amn->amn_rix > 0;
237 1.3.18.1 phil amn->amn_rix--) {
238 1.3.18.1 phil /* legacy - anything < 36mbit, stop searching */
239 1.3.18.1 phil /* 11n - stop at MCS4 */
240 1.3.18.1 phil if (amrr_node_is_11n(ni)) {
241 1.3.18.1 phil if ((rs->rs_rates[amn->amn_rix] & 0x1f) < 4)
242 1.3.18.1 phil break;
243 1.3.18.1 phil } else if ((rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL) <= 72)
244 1.3.18.1 phil break;
245 1.3.18.1 phil }
246 1.3.18.1 phil rate = rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL;
247 1.3.18.1 phil
248 1.3.18.1 phil /* if the rate is an 11n rate, ensure the MCS bit is set */
249 1.3.18.1 phil if (amrr_node_is_11n(ni))
250 1.3.18.1 phil rate |= IEEE80211_RATE_MCS;
251 1.3.18.1 phil
252 1.3.18.1 phil /* Assign initial rate from the rateset */
253 1.3.18.1 phil ni->ni_txrate = rate;
254 1.3.18.1 phil amn->amn_ticks = ticks;
255 1.3.18.1 phil
256 1.3.18.1 phil /* XXX TODO: we really need a rate-to-string method */
257 1.3.18.1 phil /* XXX TODO: non-11n rate should be divided by two.. */
258 1.3.18.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
259 1.3.18.1 phil "AMRR: nrates=%d, initial rate %s%d",
260 1.3.18.1 phil rs->rs_nrates,
261 1.3.18.1 phil amrr_node_is_11n(ni) ? "MCS " : "",
262 1.3.18.1 phil rate & IEEE80211_RATE_VAL);
263 1.1 joerg }
264 1.1 joerg
265 1.3.18.1 phil static void
266 1.3.18.1 phil amrr_node_deinit(struct ieee80211_node *ni)
267 1.1 joerg {
268 1.3.18.1 phil IEEE80211_FREE(ni->ni_rctls, M_80211_RATECTL);
269 1.3.18.1 phil }
270 1.3.18.1 phil
271 1.3.18.1 phil static int
272 1.3.18.1 phil amrr_update(struct ieee80211_amrr *amrr, struct ieee80211_amrr_node *amn,
273 1.3.18.1 phil struct ieee80211_node *ni)
274 1.3.18.1 phil {
275 1.3.18.1 phil int rix = amn->amn_rix;
276 1.3.18.1 phil const struct ieee80211_rateset *rs = NULL;
277 1.3.18.1 phil
278 1.3.18.1 phil KASSERT(is_enough(amn), ("txcnt %d", amn->amn_txcnt));
279 1.3.18.1 phil
280 1.3.18.1 phil /* 11n or not? Pick the right rateset */
281 1.3.18.1 phil if (amrr_node_is_11n(ni)) {
282 1.3.18.1 phil /* XXX ew */
283 1.3.18.1 phil rs = (struct ieee80211_rateset *) &ni->ni_htrates;
284 1.3.18.1 phil } else {
285 1.3.18.1 phil rs = &ni->ni_rates;
286 1.3.18.1 phil }
287 1.1 joerg
288 1.3.18.1 phil /* XXX TODO: we really need a rate-to-string method */
289 1.3.18.1 phil /* XXX TODO: non-11n rate should be divided by two.. */
290 1.3.18.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
291 1.3.18.1 phil "AMRR: current rate %d, txcnt=%d, retrycnt=%d",
292 1.3.18.1 phil rs->rs_rates[rix] & IEEE80211_RATE_VAL,
293 1.3.18.1 phil amn->amn_txcnt,
294 1.3.18.1 phil amn->amn_retrycnt);
295 1.3.18.1 phil
296 1.3.18.1 phil /*
297 1.3.18.1 phil * XXX This is totally bogus for 11n, as although high MCS
298 1.3.18.1 phil * rates for each stream may be failing, the next stream
299 1.3.18.1 phil * should be checked.
300 1.3.18.1 phil *
301 1.3.18.1 phil * Eg, if MCS5 is ok but MCS6/7 isn't, and we can go up to
302 1.3.18.1 phil * MCS23, we should skip 6/7 and try 8 onwards.
303 1.3.18.1 phil */
304 1.3.18.1 phil if (is_success(amn)) {
305 1.1 joerg amn->amn_success++;
306 1.1 joerg if (amn->amn_success >= amn->amn_success_threshold &&
307 1.3.18.1 phil rix + 1 < rs->rs_nrates) {
308 1.1 joerg amn->amn_recovery = 1;
309 1.1 joerg amn->amn_success = 0;
310 1.3.18.1 phil rix++;
311 1.3.18.1 phil /* XXX TODO: we really need a rate-to-string method */
312 1.3.18.1 phil /* XXX TODO: non-11n rate should be divided by two.. */
313 1.3.18.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
314 1.3.18.1 phil "AMRR increasing rate %d (txcnt=%d retrycnt=%d)",
315 1.3.18.1 phil rs->rs_rates[rix] & IEEE80211_RATE_VAL,
316 1.1 joerg amn->amn_txcnt, amn->amn_retrycnt);
317 1.1 joerg } else {
318 1.1 joerg amn->amn_recovery = 0;
319 1.1 joerg }
320 1.1 joerg } else if (is_failure(amn)) {
321 1.1 joerg amn->amn_success = 0;
322 1.3.18.1 phil if (rix > 0) {
323 1.1 joerg if (amn->amn_recovery) {
324 1.1 joerg amn->amn_success_threshold *= 2;
325 1.1 joerg if (amn->amn_success_threshold >
326 1.1 joerg amrr->amrr_max_success_threshold)
327 1.1 joerg amn->amn_success_threshold =
328 1.1 joerg amrr->amrr_max_success_threshold;
329 1.1 joerg } else {
330 1.1 joerg amn->amn_success_threshold =
331 1.1 joerg amrr->amrr_min_success_threshold;
332 1.1 joerg }
333 1.3.18.1 phil rix--;
334 1.3.18.1 phil /* XXX TODO: we really need a rate-to-string method */
335 1.3.18.1 phil /* XXX TODO: non-11n rate should be divided by two.. */
336 1.3.18.1 phil IEEE80211_NOTE(ni->ni_vap, IEEE80211_MSG_RATECTL, ni,
337 1.3.18.1 phil "AMRR decreasing rate %d (txcnt=%d retrycnt=%d)",
338 1.3.18.1 phil rs->rs_rates[rix] & IEEE80211_RATE_VAL,
339 1.1 joerg amn->amn_txcnt, amn->amn_retrycnt);
340 1.1 joerg }
341 1.1 joerg amn->amn_recovery = 0;
342 1.1 joerg }
343 1.1 joerg
344 1.3.18.1 phil /* reset counters */
345 1.3.18.1 phil amn->amn_txcnt = 0;
346 1.3.18.1 phil amn->amn_retrycnt = 0;
347 1.3.18.1 phil
348 1.3.18.1 phil return rix;
349 1.3.18.1 phil }
350 1.3.18.1 phil
351 1.3.18.1 phil /*
352 1.3.18.1 phil * Return the rate index to use in sending a data frame.
353 1.3.18.1 phil * Update our internal state if it's been long enough.
354 1.3.18.1 phil * If the rate changes we also update ni_txrate to match.
355 1.3.18.1 phil */
356 1.3.18.1 phil static int
357 1.3.18.1 phil amrr_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg __unused)
358 1.3.18.1 phil {
359 1.3.18.1 phil struct ieee80211_amrr_node *amn = ni->ni_rctls;
360 1.3.18.1 phil struct ieee80211_amrr *amrr = amn->amn_amrr;
361 1.3.18.1 phil const struct ieee80211_rateset *rs = NULL;
362 1.3.18.1 phil int rix;
363 1.3.18.1 phil
364 1.3.18.1 phil /* 11n or not? Pick the right rateset */
365 1.3.18.1 phil if (amrr_node_is_11n(ni)) {
366 1.3.18.1 phil /* XXX ew */
367 1.3.18.1 phil rs = (struct ieee80211_rateset *) &ni->ni_htrates;
368 1.3.18.1 phil } else {
369 1.3.18.1 phil rs = &ni->ni_rates;
370 1.3.18.1 phil }
371 1.3.18.1 phil
372 1.3.18.1 phil if (is_enough(amn) && (ticks - amn->amn_ticks) > amrr->amrr_interval) {
373 1.3.18.1 phil rix = amrr_update(amrr, amn, ni);
374 1.3.18.1 phil if (rix != amn->amn_rix) {
375 1.3.18.1 phil /* update public rate */
376 1.3.18.1 phil ni->ni_txrate = rs->rs_rates[rix];
377 1.3.18.1 phil /* XXX strip basic rate flag from txrate, if non-11n */
378 1.3.18.1 phil if (amrr_node_is_11n(ni))
379 1.3.18.1 phil ni->ni_txrate |= IEEE80211_RATE_MCS;
380 1.3.18.1 phil else
381 1.3.18.1 phil ni->ni_txrate &= IEEE80211_RATE_VAL;
382 1.3.18.1 phil amn->amn_rix = rix;
383 1.3.18.1 phil }
384 1.3.18.1 phil amn->amn_ticks = ticks;
385 1.3.18.1 phil } else
386 1.3.18.1 phil rix = amn->amn_rix;
387 1.3.18.1 phil return rix;
388 1.3.18.1 phil }
389 1.3.18.1 phil
390 1.3.18.1 phil /*
391 1.3.18.1 phil * Update statistics with tx complete status. Ok is non-zero
392 1.3.18.1 phil * if the packet is known to be ACK'd. Retries has the number
393 1.3.18.1 phil * retransmissions (i.e. xmit attempts - 1).
394 1.3.18.1 phil */
395 1.3.18.1 phil static void
396 1.3.18.1 phil amrr_tx_complete(const struct ieee80211_node *ni,
397 1.3.18.1 phil const struct ieee80211_ratectl_tx_status *status)
398 1.3.18.1 phil {
399 1.3.18.1 phil struct ieee80211_amrr_node *amn = ni->ni_rctls;
400 1.3.18.1 phil int retries;
401 1.3.18.1 phil
402 1.3.18.1 phil retries = 0;
403 1.3.18.1 phil if (status->flags & IEEE80211_RATECTL_STATUS_LONG_RETRY)
404 1.3.18.1 phil retries = status->long_retries;
405 1.3.18.1 phil
406 1.3.18.1 phil amn->amn_txcnt++;
407 1.3.18.1 phil if (status->status == IEEE80211_RATECTL_TX_SUCCESS)
408 1.3.18.1 phil amn->amn_success++;
409 1.3.18.1 phil amn->amn_retrycnt += retries;
410 1.3.18.1 phil }
411 1.3.18.1 phil
412 1.3.18.1 phil static void
413 1.3.18.1 phil amrr_tx_update_cb(void *arg, struct ieee80211_node *ni)
414 1.3.18.1 phil {
415 1.3.18.1 phil struct ieee80211_ratectl_tx_stats *stats = arg;
416 1.3.18.1 phil struct ieee80211_amrr_node *amn = ni->ni_rctls;
417 1.3.18.1 phil int txcnt, success, retrycnt;
418 1.3.18.1 phil
419 1.3.18.1 phil txcnt = stats->nframes;
420 1.3.18.1 phil success = stats->nsuccess;
421 1.3.18.1 phil retrycnt = 0;
422 1.3.18.1 phil if (stats->flags & IEEE80211_RATECTL_TX_STATS_RETRIES)
423 1.3.18.1 phil retrycnt = stats->nretries;
424 1.3.18.1 phil
425 1.3.18.1 phil amn->amn_txcnt += txcnt;
426 1.3.18.1 phil amn->amn_success += success;
427 1.3.18.1 phil amn->amn_retrycnt += retrycnt;
428 1.3.18.1 phil }
429 1.3.18.1 phil
430 1.3.18.1 phil /*
431 1.3.18.1 phil * Set tx count/retry statistics explicitly. Intended for
432 1.3.18.1 phil * drivers that poll the device for statistics maintained
433 1.3.18.1 phil * in the device.
434 1.3.18.1 phil */
435 1.3.18.1 phil static void
436 1.3.18.1 phil amrr_tx_update(struct ieee80211vap *vap,
437 1.3.18.1 phil struct ieee80211_ratectl_tx_stats *stats)
438 1.3.18.1 phil {
439 1.3.18.1 phil
440 1.3.18.1 phil if (stats->flags & IEEE80211_RATECTL_TX_STATS_NODE)
441 1.3.18.1 phil amrr_tx_update_cb(stats, stats->ni);
442 1.3.18.1 phil else {
443 1.3.18.1 phil ieee80211_iterate_nodes_vap(&vap->iv_ic->ic_sta, vap,
444 1.3.18.1 phil amrr_tx_update_cb, stats);
445 1.3.18.1 phil }
446 1.3.18.1 phil }
447 1.3.18.1 phil
448 1.3.18.2 phil #ifdef notyet
449 1.3.18.1 phil static int
450 1.3.18.1 phil amrr_sysctl_interval(SYSCTL_HANDLER_ARGS)
451 1.3.18.1 phil {
452 1.3.18.1 phil struct ieee80211vap *vap = arg1;
453 1.3.18.1 phil struct ieee80211_amrr *amrr = vap->iv_rs;
454 1.3.18.1 phil int msecs = ticks_to_msecs(amrr->amrr_interval);
455 1.3.18.1 phil int error;
456 1.3.18.1 phil
457 1.3.18.1 phil error = sysctl_handle_int(oidp, &msecs, 0, req);
458 1.3.18.1 phil if (error || !req->newptr)
459 1.3.18.1 phil return error;
460 1.3.18.1 phil amrr_setinterval(vap, msecs);
461 1.3.18.1 phil return 0;
462 1.3.18.1 phil }
463 1.3.18.2 phil #endif
464 1.3.18.1 phil
465 1.3.18.4 phil #ifdef notyet
466 1.3.18.1 phil static void
467 1.3.18.1 phil amrr_sysctlattach(struct ieee80211vap *vap,
468 1.3.18.1 phil struct sysctl_ctx_list *ctx, struct sysctl_oid *tree)
469 1.3.18.1 phil {
470 1.3.18.1 phil struct ieee80211_amrr *amrr = vap->iv_rs;
471 1.3.18.1 phil
472 1.3.18.1 phil SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
473 1.3.18.1 phil "amrr_rate_interval", CTLTYPE_INT | CTLFLAG_RW, vap,
474 1.3.18.1 phil 0, amrr_sysctl_interval, "I", "amrr operation interval (ms)");
475 1.3.18.1 phil /* XXX bounds check values */
476 1.3.18.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
477 1.3.18.1 phil "amrr_max_sucess_threshold", CTLFLAG_RW,
478 1.3.18.1 phil &amrr->amrr_max_success_threshold, 0, "");
479 1.3.18.1 phil SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
480 1.3.18.1 phil "amrr_min_sucess_threshold", CTLFLAG_RW,
481 1.3.18.1 phil &amrr->amrr_min_success_threshold, 0, "");
482 1.3.18.1 phil }
483 1.3.18.4 phil #endif
484 1.3.18.1 phil
485 1.3.18.1 phil static void
486 1.3.18.1 phil amrr_node_stats(struct ieee80211_node *ni, struct sbuf *s)
487 1.3.18.1 phil {
488 1.3.18.1 phil int rate;
489 1.3.18.1 phil struct ieee80211_amrr_node *amn = ni->ni_rctls;
490 1.3.18.1 phil struct ieee80211_rateset *rs;
491 1.3.18.1 phil
492 1.3.18.1 phil /* XXX TODO: check locking? */
493 1.3.18.1 phil
494 1.3.18.1 phil /* XXX TODO: this should be a method */
495 1.3.18.1 phil if (amrr_node_is_11n(ni)) {
496 1.3.18.1 phil rs = (struct ieee80211_rateset *) &ni->ni_htrates;
497 1.3.18.1 phil rate = rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL;
498 1.3.18.1 phil sbuf_printf(s, "rate: MCS %d\n", rate);
499 1.3.18.1 phil } else {
500 1.3.18.1 phil rs = &ni->ni_rates;
501 1.3.18.1 phil rate = rs->rs_rates[amn->amn_rix] & IEEE80211_RATE_VAL;
502 1.3.18.1 phil sbuf_printf(s, "rate: %d Mbit\n", rate / 2);
503 1.3.18.1 phil }
504 1.3.18.1 phil
505 1.3.18.1 phil sbuf_printf(s, "ticks: %d\n", amn->amn_ticks);
506 1.3.18.1 phil sbuf_printf(s, "txcnt: %u\n", amn->amn_txcnt);
507 1.3.18.1 phil sbuf_printf(s, "success: %u\n", amn->amn_success);
508 1.3.18.1 phil sbuf_printf(s, "success_threshold: %u\n", amn->amn_success_threshold);
509 1.3.18.1 phil sbuf_printf(s, "recovery: %u\n", amn->amn_recovery);
510 1.3.18.1 phil sbuf_printf(s, "retry_cnt: %u\n", amn->amn_retrycnt);
511 1.1 joerg }
512 1.3.18.2 phil
513