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