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