athrate-sample.c revision 1.2.2.3 1 1.2.2.3 yamt /* $NetBSD: athrate-sample.c,v 1.2.2.3 2007/10/27 11:30:31 yamt Exp $ */
2 1.2.2.1 yamt
3 1.1 dyoung /*-
4 1.1 dyoung * Copyright (c) 2005 John Bicket
5 1.1 dyoung * All rights reserved.
6 1.1 dyoung *
7 1.1 dyoung * Redistribution and use in source and binary forms, with or without
8 1.1 dyoung * modification, are permitted provided that the following conditions
9 1.1 dyoung * are met:
10 1.1 dyoung * 1. Redistributions of source code must retain the above copyright
11 1.1 dyoung * notice, this list of conditions and the following disclaimer,
12 1.1 dyoung * without modification.
13 1.1 dyoung * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14 1.1 dyoung * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
15 1.1 dyoung * redistribution must be conditioned upon including a substantially
16 1.1 dyoung * similar Disclaimer requirement for further binary redistribution.
17 1.1 dyoung * 3. Neither the names of the above-listed copyright holders nor the names
18 1.1 dyoung * of any contributors may be used to endorse or promote products derived
19 1.1 dyoung * from this software without specific prior written permission.
20 1.1 dyoung *
21 1.1 dyoung * Alternatively, this software may be distributed under the terms of the
22 1.1 dyoung * GNU General Public License ("GPL") version 2 as published by the Free
23 1.1 dyoung * Software Foundation.
24 1.1 dyoung *
25 1.1 dyoung * NO WARRANTY
26 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 1.1 dyoung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 1.1 dyoung * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
29 1.1 dyoung * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
30 1.1 dyoung * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
31 1.1 dyoung * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 dyoung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 dyoung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34 1.1 dyoung * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 dyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36 1.1 dyoung * THE POSSIBILITY OF SUCH DAMAGES.
37 1.1 dyoung */
38 1.1 dyoung
39 1.1 dyoung #include <sys/cdefs.h>
40 1.2.2.1 yamt #ifdef __FreeBSD__
41 1.2.2.1 yamt __FBSDID("$FreeBSD: src/sys/dev/ath/ath_rate/sample/sample.c,v 1.9 2005/07/22 16:50:17 sam Exp $");
42 1.2.2.1 yamt #endif
43 1.2.2.1 yamt #ifdef __NetBSD__
44 1.2.2.3 yamt __KERNEL_RCSID(0, "$NetBSD: athrate-sample.c,v 1.2.2.3 2007/10/27 11:30:31 yamt Exp $");
45 1.2.2.1 yamt #endif
46 1.2.2.1 yamt
47 1.1 dyoung
48 1.1 dyoung /*
49 1.1 dyoung * John Bicket's SampleRate control algorithm.
50 1.1 dyoung */
51 1.1 dyoung #include "opt_inet.h"
52 1.1 dyoung
53 1.1 dyoung #include <sys/param.h>
54 1.1 dyoung #include <sys/systm.h>
55 1.1 dyoung #include <sys/sysctl.h>
56 1.1 dyoung #include <sys/kernel.h>
57 1.1 dyoung #include <sys/lock.h>
58 1.1 dyoung #include <sys/errno.h>
59 1.2.2.1 yamt #include <sys/device.h>
60 1.1 dyoung
61 1.2.2.3 yamt #include <sys/bus.h>
62 1.1 dyoung
63 1.1 dyoung #include <sys/socket.h>
64 1.1 dyoung
65 1.1 dyoung #include <net/if.h>
66 1.1 dyoung #include <net/if_media.h>
67 1.1 dyoung #include <net/if_arp.h>
68 1.2.2.1 yamt #include <net/if_ether.h> /* XXX for ether_sprintf */
69 1.1 dyoung
70 1.1 dyoung #include <net80211/ieee80211_var.h>
71 1.1 dyoung
72 1.1 dyoung #include <net/bpf.h>
73 1.1 dyoung
74 1.1 dyoung #ifdef INET
75 1.1 dyoung #include <netinet/in.h>
76 1.1 dyoung #endif
77 1.1 dyoung
78 1.2 dyoung #include <dev/ic/athvar.h>
79 1.2 dyoung #include <dev/ic/athrate-sample.h>
80 1.2.2.1 yamt #include <contrib/dev/ath/ah_desc.h>
81 1.1 dyoung
82 1.1 dyoung #define SAMPLE_DEBUG
83 1.1 dyoung #ifdef SAMPLE_DEBUG
84 1.1 dyoung enum {
85 1.2.2.1 yamt ATH_DEBUG_RATE = 0x00000010 /* rate control */
86 1.1 dyoung };
87 1.1 dyoung #define DPRINTF(sc, _fmt, ...) do { \
88 1.1 dyoung if (sc->sc_debug & ATH_DEBUG_RATE) \
89 1.1 dyoung printf(_fmt, __VA_ARGS__); \
90 1.1 dyoung } while (0)
91 1.1 dyoung #else
92 1.1 dyoung #define DPRINTF(sc, _fmt, ...)
93 1.1 dyoung #endif
94 1.1 dyoung
95 1.1 dyoung /*
96 1.1 dyoung * This file is an implementation of the SampleRate algorithm
97 1.1 dyoung * in "Bit-rate Selection in Wireless Networks"
98 1.1 dyoung * (http://www.pdos.lcs.mit.edu/papers/jbicket-ms.ps)
99 1.1 dyoung *
100 1.1 dyoung * SampleRate chooses the bit-rate it predicts will provide the most
101 1.1 dyoung * throughput based on estimates of the expected per-packet
102 1.1 dyoung * transmission time for each bit-rate. SampleRate periodically sends
103 1.1 dyoung * packets at bit-rates other than the current one to estimate when
104 1.1 dyoung * another bit-rate will provide better performance. SampleRate
105 1.1 dyoung * switches to another bit-rate when its estimated per-packet
106 1.1 dyoung * transmission time becomes smaller than the current bit-rate's.
107 1.1 dyoung * SampleRate reduces the number of bit-rates it must sample by
108 1.1 dyoung * eliminating those that could not perform better than the one
109 1.1 dyoung * currently being used. SampleRate also stops probing at a bit-rate
110 1.1 dyoung * if it experiences several successive losses.
111 1.1 dyoung *
112 1.1 dyoung * The difference between the algorithm in the thesis and the one in this
113 1.1 dyoung * file is that the one in this file uses a ewma instead of a window.
114 1.1 dyoung *
115 1.2.2.1 yamt * Also, this implementation tracks the average transmission time for
116 1.2.2.1 yamt * a few different packet sizes independently for each link.
117 1.1 dyoung */
118 1.1 dyoung
119 1.1 dyoung #define STALE_FAILURE_TIMEOUT_MS 10000
120 1.2.2.1 yamt #define MIN_SWITCH_MS 1000
121 1.1 dyoung
122 1.1 dyoung static void ath_rate_ctl_reset(struct ath_softc *, struct ieee80211_node *);
123 1.1 dyoung
124 1.2.2.1 yamt static inline int
125 1.2.2.1 yamt size_to_bin(int size)
126 1.1 dyoung {
127 1.1 dyoung int x = 0;
128 1.1 dyoung for (x = 0; x < NUM_PACKET_SIZE_BINS; x++) {
129 1.1 dyoung if (size <= packet_size_bins[x]) {
130 1.1 dyoung return x;
131 1.1 dyoung }
132 1.1 dyoung }
133 1.1 dyoung return NUM_PACKET_SIZE_BINS-1;
134 1.1 dyoung }
135 1.2.2.1 yamt static inline int bin_to_size(int index) {
136 1.1 dyoung return packet_size_bins[index];
137 1.1 dyoung }
138 1.1 dyoung
139 1.2.2.1 yamt static inline int
140 1.2.2.1 yamt rate_to_ndx(struct sample_node *sn, int rate) {
141 1.1 dyoung int x = 0;
142 1.1 dyoung for (x = 0; x < sn->num_rates; x++) {
143 1.1 dyoung if (sn->rates[x].rate == rate) {
144 1.1 dyoung return x;
145 1.1 dyoung }
146 1.1 dyoung }
147 1.1 dyoung return -1;
148 1.1 dyoung }
149 1.1 dyoung
150 1.1 dyoung void
151 1.1 dyoung ath_rate_node_init(struct ath_softc *sc, struct ath_node *an)
152 1.1 dyoung {
153 1.1 dyoung DPRINTF(sc, "%s:\n", __func__);
154 1.1 dyoung /* NB: assumed to be zero'd by caller */
155 1.1 dyoung }
156 1.1 dyoung
157 1.1 dyoung void
158 1.1 dyoung ath_rate_node_cleanup(struct ath_softc *sc, struct ath_node *an)
159 1.1 dyoung {
160 1.1 dyoung DPRINTF(sc, "%s:\n", __func__);
161 1.1 dyoung }
162 1.1 dyoung
163 1.1 dyoung
164 1.1 dyoung /*
165 1.1 dyoung * returns the ndx with the lowest average_tx_time,
166 1.1 dyoung * or -1 if all the average_tx_times are 0.
167 1.1 dyoung */
168 1.2.2.1 yamt static inline int best_rate_ndx(struct sample_node *sn, int size_bin,
169 1.1 dyoung int require_acked_before)
170 1.1 dyoung {
171 1.1 dyoung int x = 0;
172 1.2.2.1 yamt int best_ndx = 0;
173 1.1 dyoung int best_rate_tt = 0;
174 1.1 dyoung for (x = 0; x < sn->num_rates; x++) {
175 1.1 dyoung int tt = sn->stats[size_bin][x].average_tx_time;
176 1.1 dyoung if (tt <= 0 || (require_acked_before &&
177 1.1 dyoung !sn->stats[size_bin][x].packets_acked)) {
178 1.1 dyoung continue;
179 1.1 dyoung }
180 1.2.2.1 yamt
181 1.2.2.1 yamt /* 9 megabits never works better than 12 */
182 1.2.2.1 yamt if (sn->rates[x].rate == 18)
183 1.2.2.1 yamt continue;
184 1.2.2.1 yamt
185 1.2.2.1 yamt /* don't use a bit-rate that has been failing */
186 1.2.2.1 yamt if (sn->stats[size_bin][x].successive_failures > 3)
187 1.2.2.1 yamt continue;
188 1.2.2.1 yamt
189 1.1 dyoung if (!best_rate_tt || best_rate_tt > tt) {
190 1.1 dyoung best_rate_tt = tt;
191 1.2.2.1 yamt best_ndx = x;
192 1.1 dyoung }
193 1.1 dyoung }
194 1.2.2.1 yamt return (best_rate_tt) ? best_ndx : -1;
195 1.1 dyoung }
196 1.1 dyoung
197 1.1 dyoung /*
198 1.2.2.1 yamt * pick a good "random" bit-rate to sample other than the current one
199 1.1 dyoung */
200 1.2.2.1 yamt static inline int
201 1.2.2.1 yamt pick_sample_ndx(struct sample_node *sn, int size_bin)
202 1.1 dyoung {
203 1.1 dyoung int x = 0;
204 1.1 dyoung int current_ndx = 0;
205 1.1 dyoung unsigned current_tt = 0;
206 1.1 dyoung
207 1.1 dyoung current_ndx = sn->current_rate[size_bin];
208 1.1 dyoung if (current_ndx < 0) {
209 1.1 dyoung /* no successes yet, send at the lowest bit-rate */
210 1.1 dyoung return 0;
211 1.1 dyoung }
212 1.1 dyoung
213 1.1 dyoung current_tt = sn->stats[size_bin][current_ndx].average_tx_time;
214 1.1 dyoung
215 1.1 dyoung for (x = 0; x < sn->num_rates; x++) {
216 1.2.2.1 yamt int ndx = (sn->last_sample_ndx[size_bin]+1+x) % sn->num_rates;
217 1.2.2.1 yamt
218 1.2.2.1 yamt /* don't sample the current bit-rate */
219 1.2.2.1 yamt if (ndx == current_ndx)
220 1.2.2.1 yamt continue;
221 1.2.2.1 yamt
222 1.2.2.1 yamt /* this bit-rate is always worse than the current one */
223 1.2.2.1 yamt if (sn->stats[size_bin][ndx].perfect_tx_time > current_tt)
224 1.2.2.1 yamt continue;
225 1.2.2.1 yamt
226 1.2.2.1 yamt /* rarely sample bit-rates that fail a lot */
227 1.2.2.1 yamt if (ticks - sn->stats[size_bin][ndx].last_tx < ((hz * STALE_FAILURE_TIMEOUT_MS)/1000) &&
228 1.2.2.1 yamt sn->stats[size_bin][ndx].successive_failures > 3)
229 1.2.2.1 yamt continue;
230 1.2.2.1 yamt
231 1.2.2.1 yamt /* don't sample more than 2 indexes higher
232 1.2.2.1 yamt * for rates higher than 11 megabits
233 1.1 dyoung */
234 1.2.2.1 yamt if (sn->rates[ndx].rate > 22 && ndx > current_ndx + 2)
235 1.2.2.1 yamt continue;
236 1.1 dyoung
237 1.2.2.1 yamt /* 9 megabits never works better than 12 */
238 1.2.2.1 yamt if (sn->rates[ndx].rate == 18)
239 1.2.2.1 yamt continue;
240 1.2.2.1 yamt
241 1.2.2.1 yamt /* if we're using 11 megabits, only sample up to 12 megabits
242 1.2.2.1 yamt */
243 1.2.2.1 yamt if (sn->rates[current_ndx].rate == 22 && ndx > current_ndx + 1)
244 1.2.2.1 yamt continue;
245 1.2.2.1 yamt
246 1.2.2.1 yamt sn->last_sample_ndx[size_bin] = ndx;
247 1.2.2.1 yamt return ndx;
248 1.1 dyoung }
249 1.1 dyoung return current_ndx;
250 1.1 dyoung }
251 1.1 dyoung
252 1.1 dyoung void
253 1.1 dyoung ath_rate_findrate(struct ath_softc *sc, struct ath_node *an,
254 1.1 dyoung int shortPreamble, size_t frameLen,
255 1.1 dyoung u_int8_t *rix, int *try0, u_int8_t *txrate)
256 1.1 dyoung {
257 1.1 dyoung struct sample_node *sn = ATH_NODE_SAMPLE(an);
258 1.1 dyoung struct sample_softc *ssc = ATH_SOFTC_SAMPLE(sc);
259 1.1 dyoung struct ieee80211com *ic = &sc->sc_ic;
260 1.2.2.1 yamt int ndx, size_bin, mrr, best_ndx, change_rates;
261 1.1 dyoung unsigned average_tx_time;
262 1.1 dyoung
263 1.2.2.1 yamt mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT);
264 1.1 dyoung size_bin = size_to_bin(frameLen);
265 1.1 dyoung best_ndx = best_rate_ndx(sn, size_bin, !mrr);
266 1.1 dyoung
267 1.1 dyoung if (best_ndx >= 0) {
268 1.1 dyoung average_tx_time = sn->stats[size_bin][best_ndx].average_tx_time;
269 1.1 dyoung } else {
270 1.1 dyoung average_tx_time = 0;
271 1.1 dyoung }
272 1.2.2.1 yamt
273 1.1 dyoung if (sn->static_rate_ndx != -1) {
274 1.1 dyoung ndx = sn->static_rate_ndx;
275 1.1 dyoung *try0 = ATH_TXMAXTRY;
276 1.1 dyoung } else {
277 1.1 dyoung *try0 = mrr ? 2 : ATH_TXMAXTRY;
278 1.2.2.1 yamt
279 1.2.2.1 yamt if (sn->sample_tt[size_bin] < average_tx_time * (sn->packets_since_sample[size_bin]*ssc->ath_sample_rate/100)) {
280 1.1 dyoung /*
281 1.1 dyoung * we want to limit the time measuring the performance
282 1.1 dyoung * of other bit-rates to ath_sample_rate% of the
283 1.1 dyoung * total transmission time.
284 1.1 dyoung */
285 1.1 dyoung ndx = pick_sample_ndx(sn, size_bin);
286 1.1 dyoung if (ndx != sn->current_rate[size_bin]) {
287 1.1 dyoung sn->current_sample_ndx[size_bin] = ndx;
288 1.1 dyoung } else {
289 1.1 dyoung sn->current_sample_ndx[size_bin] = -1;
290 1.1 dyoung }
291 1.1 dyoung sn->packets_since_sample[size_bin] = 0;
292 1.1 dyoung
293 1.1 dyoung } else {
294 1.2.2.1 yamt change_rates = 0;
295 1.2.2.1 yamt if (!sn->packets_sent[size_bin] || best_ndx == -1) {
296 1.2.2.1 yamt /* no packet has been sent successfully yet */
297 1.2.2.1 yamt for (ndx = sn->num_rates-1; ndx > 0; ndx--) {
298 1.2.2.1 yamt /*
299 1.2.2.1 yamt * pick the highest rate <= 36 Mbps
300 1.2.2.1 yamt * that hasn't failed.
301 1.2.2.1 yamt */
302 1.2.2.1 yamt if (sn->rates[ndx].rate <= 72 &&
303 1.2.2.1 yamt sn->stats[size_bin][ndx].successive_failures == 0) {
304 1.2.2.1 yamt break;
305 1.2.2.1 yamt }
306 1.2.2.1 yamt }
307 1.2.2.1 yamt change_rates = 1;
308 1.2.2.1 yamt best_ndx = ndx;
309 1.2.2.1 yamt } else if (sn->packets_sent[size_bin] < 20) {
310 1.2.2.1 yamt /* let the bit-rate switch quickly during the first few packets */
311 1.2.2.1 yamt change_rates = 1;
312 1.2.2.1 yamt } else if (ticks - ((hz*MIN_SWITCH_MS)/1000) > sn->ticks_since_switch[size_bin]) {
313 1.2.2.1 yamt /* 2 seconds have gone by */
314 1.2.2.1 yamt change_rates = 1;
315 1.2.2.1 yamt } else if (average_tx_time * 2 < sn->stats[size_bin][sn->current_rate[size_bin]].average_tx_time) {
316 1.2.2.1 yamt /* the current bit-rate is twice as slow as the best one */
317 1.2.2.1 yamt change_rates = 1;
318 1.2.2.1 yamt }
319 1.2.2.1 yamt
320 1.1 dyoung sn->packets_since_sample[size_bin]++;
321 1.2.2.1 yamt
322 1.2.2.1 yamt if (change_rates) {
323 1.2.2.1 yamt if (best_ndx != sn->current_rate[size_bin]) {
324 1.2.2.1 yamt DPRINTF(sc, "%s: %s size %d switch rate %d (%d/%d) -> %d (%d/%d) after %d packets mrr %d\n",
325 1.1 dyoung __func__,
326 1.1 dyoung ether_sprintf(an->an_node.ni_macaddr),
327 1.1 dyoung packet_size_bins[size_bin],
328 1.1 dyoung sn->rates[sn->current_rate[size_bin]].rate,
329 1.1 dyoung sn->stats[size_bin][sn->current_rate[size_bin]].average_tx_time,
330 1.1 dyoung sn->stats[size_bin][sn->current_rate[size_bin]].perfect_tx_time,
331 1.1 dyoung sn->rates[best_ndx].rate,
332 1.1 dyoung sn->stats[size_bin][best_ndx].average_tx_time,
333 1.1 dyoung sn->stats[size_bin][best_ndx].perfect_tx_time,
334 1.1 dyoung sn->packets_since_switch[size_bin],
335 1.1 dyoung mrr);
336 1.1 dyoung }
337 1.1 dyoung sn->packets_since_switch[size_bin] = 0;
338 1.1 dyoung sn->current_rate[size_bin] = best_ndx;
339 1.2.2.1 yamt sn->ticks_since_switch[size_bin] = ticks;
340 1.1 dyoung }
341 1.1 dyoung ndx = sn->current_rate[size_bin];
342 1.1 dyoung sn->packets_since_switch[size_bin]++;
343 1.2.2.1 yamt if (size_bin == 0) {
344 1.2.2.1 yamt /*
345 1.2.2.1 yamt * set the visible txrate for this node
346 1.2.2.1 yamt * to the rate of small packets
347 1.2.2.1 yamt */
348 1.2.2.1 yamt an->an_node.ni_txrate = ndx;
349 1.2.2.1 yamt }
350 1.1 dyoung }
351 1.1 dyoung }
352 1.1 dyoung
353 1.2.2.1 yamt KASSERT(ndx >= 0 && ndx < sn->num_rates, ("ndx is %d", ndx));
354 1.2.2.1 yamt
355 1.1 dyoung *rix = sn->rates[ndx].rix;
356 1.1 dyoung if (shortPreamble) {
357 1.1 dyoung *txrate = sn->rates[ndx].shortPreambleRateCode;
358 1.1 dyoung } else {
359 1.1 dyoung *txrate = sn->rates[ndx].rateCode;
360 1.1 dyoung }
361 1.1 dyoung sn->packets_sent[size_bin]++;
362 1.1 dyoung }
363 1.1 dyoung
364 1.1 dyoung void
365 1.1 dyoung ath_rate_setupxtxdesc(struct ath_softc *sc, struct ath_node *an,
366 1.2.2.2 yamt struct ath_desc *ds, int shortPreamble, u_int8_t rix)
367 1.1 dyoung {
368 1.1 dyoung struct sample_node *sn = ATH_NODE_SAMPLE(an);
369 1.1 dyoung int rateCode = -1;
370 1.2.2.1 yamt int frame_size = 0;
371 1.2.2.1 yamt int size_bin = 0;
372 1.2.2.1 yamt int ndx = 0;
373 1.1 dyoung
374 1.2.2.1 yamt size_bin = size_to_bin(frame_size); // TODO: it's correct that frame_size alway 0 ?
375 1.2.2.1 yamt ndx = sn->current_rate[size_bin]; /* retry at the current bit-rate */
376 1.2.2.1 yamt
377 1.2.2.1 yamt if (!sn->stats[size_bin][ndx].packets_acked) {
378 1.2.2.1 yamt ndx = 0; /* use the lowest bit-rate */
379 1.1 dyoung }
380 1.2.2.1 yamt
381 1.1 dyoung if (shortPreamble) {
382 1.1 dyoung rateCode = sn->rates[ndx].shortPreambleRateCode;
383 1.1 dyoung } else {
384 1.1 dyoung rateCode = sn->rates[ndx].rateCode;
385 1.1 dyoung }
386 1.1 dyoung ath_hal_setupxtxdesc(sc->sc_ah, ds
387 1.1 dyoung , rateCode, 3 /* series 1 */
388 1.1 dyoung , sn->rates[0].rateCode, 3 /* series 2 */
389 1.1 dyoung , 0, 0 /* series 3 */
390 1.1 dyoung );
391 1.1 dyoung }
392 1.1 dyoung
393 1.1 dyoung static void
394 1.1 dyoung update_stats(struct ath_softc *sc, struct ath_node *an,
395 1.1 dyoung int frame_size,
396 1.1 dyoung int ndx0, int tries0,
397 1.1 dyoung int ndx1, int tries1,
398 1.1 dyoung int ndx2, int tries2,
399 1.1 dyoung int ndx3, int tries3,
400 1.1 dyoung int short_tries, int tries, int status)
401 1.1 dyoung {
402 1.1 dyoung struct sample_node *sn = ATH_NODE_SAMPLE(an);
403 1.1 dyoung struct sample_softc *ssc = ATH_SOFTC_SAMPLE(sc);
404 1.1 dyoung int tt = 0;
405 1.1 dyoung int tries_so_far = 0;
406 1.2.2.1 yamt int size_bin;
407 1.2.2.1 yamt int size;
408 1.2.2.1 yamt int rate;
409 1.2.2.1 yamt
410 1.2.2.1 yamt if (ndx0 == -1)
411 1.2.2.1 yamt return;
412 1.1 dyoung
413 1.1 dyoung size_bin = size_to_bin(frame_size);
414 1.1 dyoung size = bin_to_size(size_bin);
415 1.1 dyoung rate = sn->rates[ndx0].rate;
416 1.1 dyoung
417 1.2.2.1 yamt tt += calc_usecs_unicast_packet(sc, size, sn->rates[ndx0].rix,
418 1.2.2.1 yamt short_tries - 1, MIN(tries0, tries) - 1);
419 1.1 dyoung tries_so_far += tries0;
420 1.1 dyoung if (tries1 && tries0 < tries) {
421 1.2.2.1 yamt tt += calc_usecs_unicast_packet(sc, size,
422 1.2.2.1 yamt ndx1 == -1 ? 0 : sn->rates[ndx1].rix, short_tries - 1,
423 1.2.2.1 yamt MIN(tries1 + tries_so_far, tries) - tries_so_far - 1);
424 1.1 dyoung }
425 1.1 dyoung tries_so_far += tries1;
426 1.1 dyoung
427 1.1 dyoung if (tries2 && tries0 + tries1 < tries) {
428 1.2.2.1 yamt tt += calc_usecs_unicast_packet(sc, size,
429 1.2.2.1 yamt ndx2 == -1 ? 0 : sn->rates[ndx2].rix, short_tries - 1,
430 1.2.2.1 yamt MIN(tries2 + tries_so_far, tries) - tries_so_far - 1);
431 1.1 dyoung }
432 1.1 dyoung
433 1.1 dyoung tries_so_far += tries2;
434 1.1 dyoung
435 1.1 dyoung if (tries3 && tries0 + tries1 + tries2 < tries) {
436 1.2.2.1 yamt tt += calc_usecs_unicast_packet(sc, size,
437 1.2.2.1 yamt ndx3 == -1 ? 0 : sn->rates[ndx3].rix, short_tries - 1,
438 1.2.2.1 yamt MIN(tries3 + tries_so_far, tries) - tries_so_far - 1);
439 1.1 dyoung }
440 1.2.2.1 yamt
441 1.1 dyoung if (sn->stats[size_bin][ndx0].total_packets < (100 / (100 - ssc->ath_smoothing_rate))) {
442 1.1 dyoung /* just average the first few packets */
443 1.1 dyoung int avg_tx = sn->stats[size_bin][ndx0].average_tx_time;
444 1.1 dyoung int packets = sn->stats[size_bin][ndx0].total_packets;
445 1.1 dyoung sn->stats[size_bin][ndx0].average_tx_time = (tt+(avg_tx*packets))/(packets+1);
446 1.1 dyoung } else {
447 1.1 dyoung /* use a ewma */
448 1.1 dyoung sn->stats[size_bin][ndx0].average_tx_time =
449 1.1 dyoung ((sn->stats[size_bin][ndx0].average_tx_time * ssc->ath_smoothing_rate) +
450 1.1 dyoung (tt * (100 - ssc->ath_smoothing_rate))) / 100;
451 1.1 dyoung }
452 1.1 dyoung
453 1.1 dyoung if (status) {
454 1.1 dyoung int y;
455 1.2.2.1 yamt sn->stats[size_bin][ndx0].successive_failures++;
456 1.2.2.1 yamt for (y = size_bin+1; y < NUM_PACKET_SIZE_BINS; y++) {
457 1.2.2.1 yamt /* also say larger packets failed since we
458 1.2.2.1 yamt * assume if a small packet fails at a lower
459 1.2.2.1 yamt * bit-rate then a larger one will also.
460 1.2.2.1 yamt */
461 1.1 dyoung sn->stats[y][ndx0].successive_failures++;
462 1.1 dyoung sn->stats[y][ndx0].last_tx = ticks;
463 1.2.2.1 yamt sn->stats[y][ndx0].tries += tries;
464 1.2.2.1 yamt sn->stats[y][ndx0].total_packets++;
465 1.1 dyoung }
466 1.1 dyoung } else {
467 1.1 dyoung sn->stats[size_bin][ndx0].packets_acked++;
468 1.1 dyoung sn->stats[size_bin][ndx0].successive_failures = 0;
469 1.1 dyoung }
470 1.1 dyoung sn->stats[size_bin][ndx0].tries += tries;
471 1.1 dyoung sn->stats[size_bin][ndx0].last_tx = ticks;
472 1.1 dyoung sn->stats[size_bin][ndx0].total_packets++;
473 1.1 dyoung
474 1.1 dyoung
475 1.1 dyoung if (ndx0 == sn->current_sample_ndx[size_bin]) {
476 1.1 dyoung DPRINTF(sc, "%s: %s size %d sample rate %d tries (%d/%d) tt %d avg_tt (%d/%d) status %d\n",
477 1.1 dyoung __func__, ether_sprintf(an->an_node.ni_macaddr),
478 1.1 dyoung size, rate, short_tries, tries, tt,
479 1.1 dyoung sn->stats[size_bin][ndx0].average_tx_time,
480 1.1 dyoung sn->stats[size_bin][ndx0].perfect_tx_time,
481 1.1 dyoung status);
482 1.1 dyoung sn->sample_tt[size_bin] = tt;
483 1.1 dyoung sn->current_sample_ndx[size_bin] = -1;
484 1.1 dyoung }
485 1.1 dyoung }
486 1.1 dyoung
487 1.1 dyoung void
488 1.1 dyoung ath_rate_tx_complete(struct ath_softc *sc, struct ath_node *an,
489 1.1 dyoung const struct ath_desc *ds, const struct ath_desc *ds0)
490 1.1 dyoung {
491 1.2.2.1 yamt struct ieee80211com *ic = &sc->sc_ic;
492 1.1 dyoung struct sample_node *sn = ATH_NODE_SAMPLE(an);
493 1.1 dyoung const struct ar5212_desc *ads = (const struct ar5212_desc *)&ds->ds_ctl0;
494 1.1 dyoung int final_rate, short_tries, long_tries, frame_size;
495 1.1 dyoung int ndx = -1;
496 1.2.2.1 yamt int mrr;
497 1.1 dyoung
498 1.1 dyoung final_rate = sc->sc_hwmap[ds->ds_txstat.ts_rate &~ HAL_TXSTAT_ALTRATE].ieeerate;
499 1.1 dyoung short_tries = ds->ds_txstat.ts_shortretry + 1;
500 1.1 dyoung long_tries = ds->ds_txstat.ts_longretry + 1;
501 1.1 dyoung frame_size = ds0->ds_ctl0 & 0x0fff; /* low-order 12 bits of ds_ctl0 */
502 1.1 dyoung if (frame_size == 0) /* NB: should not happen */
503 1.1 dyoung frame_size = 1500;
504 1.1 dyoung
505 1.1 dyoung if (sn->num_rates <= 0) {
506 1.1 dyoung DPRINTF(sc, "%s: %s size %d status %d rate/try %d/%d "
507 1.1 dyoung "no rates yet\n",
508 1.1 dyoung __func__, ether_sprintf(an->an_node.ni_macaddr),
509 1.1 dyoung bin_to_size(size_to_bin(frame_size)),
510 1.1 dyoung ds->ds_txstat.ts_status,
511 1.1 dyoung short_tries, long_tries);
512 1.1 dyoung return;
513 1.1 dyoung }
514 1.1 dyoung
515 1.2.2.1 yamt mrr = sc->sc_mrretry && !(ic->ic_flags & IEEE80211_F_USEPROT);
516 1.2.2.1 yamt
517 1.1 dyoung if (sc->sc_mrretry && ds->ds_txstat.ts_status) {
518 1.1 dyoung /* this packet failed */
519 1.1 dyoung DPRINTF(sc, "%s: %s size %d rate/try %d/%d %d/%d %d/%d %d/%d status %s retries (%d/%d)\n",
520 1.1 dyoung __func__,
521 1.1 dyoung ether_sprintf(an->an_node.ni_macaddr),
522 1.1 dyoung bin_to_size(size_to_bin(frame_size)),
523 1.1 dyoung sc->sc_hwmap[ads->xmit_rate0].ieeerate,
524 1.1 dyoung ads->xmit_tries0,
525 1.1 dyoung sc->sc_hwmap[ads->xmit_rate1].ieeerate,
526 1.1 dyoung ads->xmit_tries1,
527 1.1 dyoung sc->sc_hwmap[ads->xmit_rate2].ieeerate,
528 1.1 dyoung ads->xmit_tries2,
529 1.1 dyoung sc->sc_hwmap[ads->xmit_rate3].ieeerate,
530 1.1 dyoung ads->xmit_tries3,
531 1.1 dyoung ds->ds_txstat.ts_status ? "FAIL" : "OK",
532 1.1 dyoung short_tries,
533 1.1 dyoung long_tries);
534 1.1 dyoung }
535 1.1 dyoung
536 1.2.2.1 yamt if (!mrr || !(ds->ds_txstat.ts_rate & HAL_TXSTAT_ALTRATE)) {
537 1.1 dyoung /* only one rate was used */
538 1.1 dyoung ndx = rate_to_ndx(sn, final_rate);
539 1.1 dyoung DPRINTF(sc, "%s: %s size %d status %d rate/try %d/%d/%d\n",
540 1.1 dyoung __func__, ether_sprintf(an->an_node.ni_macaddr),
541 1.1 dyoung bin_to_size(size_to_bin(frame_size)),
542 1.1 dyoung ds->ds_txstat.ts_status,
543 1.1 dyoung ndx, short_tries, long_tries);
544 1.1 dyoung if (ndx >= 0 && ndx < sn->num_rates) {
545 1.1 dyoung update_stats(sc, an, frame_size,
546 1.1 dyoung ndx, long_tries,
547 1.1 dyoung 0, 0,
548 1.1 dyoung 0, 0,
549 1.1 dyoung 0, 0,
550 1.1 dyoung short_tries, long_tries, ds->ds_txstat.ts_status);
551 1.1 dyoung }
552 1.1 dyoung } else {
553 1.1 dyoung int rate0, tries0, ndx0;
554 1.1 dyoung int rate1, tries1, ndx1;
555 1.1 dyoung int rate2, tries2, ndx2;
556 1.1 dyoung int rate3, tries3, ndx3;
557 1.1 dyoung int finalTSIdx = ads->final_ts_index;
558 1.1 dyoung
559 1.1 dyoung /*
560 1.1 dyoung * Process intermediate rates that failed.
561 1.1 dyoung */
562 1.1 dyoung
563 1.1 dyoung rate0 = sc->sc_hwmap[ads->xmit_rate0].ieeerate;
564 1.1 dyoung tries0 = ads->xmit_tries0;
565 1.1 dyoung ndx0 = rate_to_ndx(sn, rate0);
566 1.1 dyoung
567 1.1 dyoung rate1 = sc->sc_hwmap[ads->xmit_rate1].ieeerate;
568 1.1 dyoung tries1 = ads->xmit_tries1;
569 1.1 dyoung ndx1 = rate_to_ndx(sn, rate1);
570 1.1 dyoung
571 1.1 dyoung rate2 = sc->sc_hwmap[ads->xmit_rate2].ieeerate;
572 1.1 dyoung tries2 = ads->xmit_tries2;
573 1.1 dyoung ndx2 = rate_to_ndx(sn, rate2);
574 1.1 dyoung
575 1.1 dyoung rate3 = sc->sc_hwmap[ads->xmit_rate3].ieeerate;
576 1.1 dyoung tries3 = ads->xmit_tries3;
577 1.1 dyoung ndx3 = rate_to_ndx(sn, rate3);
578 1.1 dyoung
579 1.1 dyoung #if 1
580 1.1 dyoung DPRINTF(sc, "%s: %s size %d finaltsidx %d tries %d status %d rate/try %d/%d %d/%d %d/%d %d/%d\n",
581 1.1 dyoung __func__, ether_sprintf(an->an_node.ni_macaddr),
582 1.1 dyoung bin_to_size(size_to_bin(frame_size)),
583 1.1 dyoung finalTSIdx,
584 1.1 dyoung long_tries,
585 1.1 dyoung ds->ds_txstat.ts_status,
586 1.1 dyoung rate0, tries0,
587 1.1 dyoung rate1, tries1,
588 1.1 dyoung rate2, tries2,
589 1.1 dyoung rate3, tries3);
590 1.1 dyoung #endif
591 1.1 dyoung
592 1.1 dyoung if (tries0) {
593 1.1 dyoung update_stats(sc, an, frame_size,
594 1.1 dyoung ndx0, tries0,
595 1.1 dyoung ndx1, tries1,
596 1.1 dyoung ndx2, tries2,
597 1.1 dyoung ndx3, tries3,
598 1.1 dyoung short_tries, ds->ds_txstat.ts_longretry + 1,
599 1.2.2.1 yamt long_tries > tries0);
600 1.1 dyoung }
601 1.1 dyoung
602 1.1 dyoung if (tries1 && finalTSIdx > 0) {
603 1.1 dyoung update_stats(sc, an, frame_size,
604 1.1 dyoung ndx1, tries1,
605 1.1 dyoung ndx2, tries2,
606 1.1 dyoung ndx3, tries3,
607 1.1 dyoung 0, 0,
608 1.1 dyoung short_tries, ds->ds_txstat.ts_longretry + 1 - tries0,
609 1.1 dyoung ds->ds_txstat.ts_status);
610 1.1 dyoung }
611 1.1 dyoung
612 1.1 dyoung if (tries2 && finalTSIdx > 1) {
613 1.1 dyoung update_stats(sc, an, frame_size,
614 1.1 dyoung ndx2, tries2,
615 1.1 dyoung ndx3, tries3,
616 1.1 dyoung 0, 0,
617 1.1 dyoung 0, 0,
618 1.1 dyoung short_tries, ds->ds_txstat.ts_longretry + 1 - tries0 - tries1,
619 1.1 dyoung ds->ds_txstat.ts_status);
620 1.1 dyoung }
621 1.1 dyoung
622 1.1 dyoung if (tries3 && finalTSIdx > 2) {
623 1.1 dyoung update_stats(sc, an, frame_size,
624 1.1 dyoung ndx3, tries3,
625 1.1 dyoung 0, 0,
626 1.1 dyoung 0, 0,
627 1.1 dyoung 0, 0,
628 1.1 dyoung short_tries, ds->ds_txstat.ts_longretry + 1 - tries0 - tries1 - tries2,
629 1.1 dyoung ds->ds_txstat.ts_status);
630 1.1 dyoung }
631 1.1 dyoung }
632 1.1 dyoung }
633 1.1 dyoung
634 1.1 dyoung void
635 1.1 dyoung ath_rate_newassoc(struct ath_softc *sc, struct ath_node *an, int isnew)
636 1.1 dyoung {
637 1.1 dyoung DPRINTF(sc, "%s: %s isnew %d\n", __func__,
638 1.1 dyoung ether_sprintf(an->an_node.ni_macaddr), isnew);
639 1.1 dyoung if (isnew)
640 1.1 dyoung ath_rate_ctl_reset(sc, &an->an_node);
641 1.1 dyoung }
642 1.1 dyoung
643 1.1 dyoung /*
644 1.1 dyoung * Initialize the tables for a node.
645 1.1 dyoung */
646 1.1 dyoung static void
647 1.1 dyoung ath_rate_ctl_reset(struct ath_softc *sc, struct ieee80211_node *ni)
648 1.1 dyoung {
649 1.1 dyoung #define RATE(_ix) (ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL)
650 1.1 dyoung struct ieee80211com *ic = &sc->sc_ic;
651 1.1 dyoung struct ath_node *an = ATH_NODE(ni);
652 1.1 dyoung struct sample_node *sn = ATH_NODE_SAMPLE(an);
653 1.1 dyoung const HAL_RATE_TABLE *rt = sc->sc_currates;
654 1.1 dyoung int x, y, srate;
655 1.1 dyoung
656 1.1 dyoung KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
657 1.1 dyoung sn->static_rate_ndx = -1;
658 1.2.2.1 yamt if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE) {
659 1.1 dyoung /*
660 1.1 dyoung * A fixed rate is to be used; ic_fixed_rate is an
661 1.1 dyoung * index into the supported rate set. Convert this
662 1.1 dyoung * to the index into the negotiated rate set for
663 1.1 dyoung * the node. We know the rate is there because the
664 1.1 dyoung * rate set is checked when the station associates.
665 1.1 dyoung */
666 1.1 dyoung const struct ieee80211_rateset *rs =
667 1.1 dyoung &ic->ic_sup_rates[ic->ic_curmode];
668 1.1 dyoung int r = rs->rs_rates[ic->ic_fixed_rate] & IEEE80211_RATE_VAL;
669 1.1 dyoung /* NB: the rate set is assumed sorted */
670 1.1 dyoung srate = ni->ni_rates.rs_nrates - 1;
671 1.1 dyoung for (; srate >= 0 && RATE(srate) != r; srate--)
672 1.1 dyoung ;
673 1.1 dyoung KASSERT(srate >= 0,
674 1.1 dyoung ("fixed rate %d not in rate set", ic->ic_fixed_rate));
675 1.1 dyoung sn->static_rate_ndx = srate;
676 1.1 dyoung }
677 1.1 dyoung
678 1.1 dyoung DPRINTF(sc, "%s: %s size 1600 rate/tt", __func__, ether_sprintf(ni->ni_macaddr));
679 1.1 dyoung
680 1.1 dyoung sn->num_rates = ni->ni_rates.rs_nrates;
681 1.1 dyoung for (x = 0; x < ni->ni_rates.rs_nrates; x++) {
682 1.1 dyoung sn->rates[x].rate = ni->ni_rates.rs_rates[x] & IEEE80211_RATE_VAL;
683 1.1 dyoung sn->rates[x].rix = sc->sc_rixmap[sn->rates[x].rate];
684 1.1 dyoung sn->rates[x].rateCode = rt->info[sn->rates[x].rix].rateCode;
685 1.1 dyoung sn->rates[x].shortPreambleRateCode =
686 1.1 dyoung rt->info[sn->rates[x].rix].rateCode |
687 1.1 dyoung rt->info[sn->rates[x].rix].shortPreamble;
688 1.1 dyoung
689 1.1 dyoung DPRINTF(sc, " %d/%d", sn->rates[x].rate,
690 1.1 dyoung calc_usecs_unicast_packet(sc, 1600, sn->rates[x].rix,
691 1.1 dyoung 0,0));
692 1.1 dyoung }
693 1.1 dyoung DPRINTF(sc, "%s\n", "");
694 1.1 dyoung
695 1.1 dyoung /* set the visible bit-rate to the lowest one available */
696 1.1 dyoung ni->ni_txrate = 0;
697 1.1 dyoung sn->num_rates = ni->ni_rates.rs_nrates;
698 1.1 dyoung
699 1.1 dyoung for (y = 0; y < NUM_PACKET_SIZE_BINS; y++) {
700 1.1 dyoung int size = bin_to_size(y);
701 1.2.2.1 yamt int ndx = 0;
702 1.1 dyoung sn->packets_sent[y] = 0;
703 1.1 dyoung sn->current_sample_ndx[y] = -1;
704 1.1 dyoung sn->last_sample_ndx[y] = 0;
705 1.1 dyoung
706 1.1 dyoung for (x = 0; x < ni->ni_rates.rs_nrates; x++) {
707 1.1 dyoung sn->stats[y][x].successive_failures = 0;
708 1.1 dyoung sn->stats[y][x].tries = 0;
709 1.1 dyoung sn->stats[y][x].total_packets = 0;
710 1.1 dyoung sn->stats[y][x].packets_acked = 0;
711 1.1 dyoung sn->stats[y][x].last_tx = 0;
712 1.1 dyoung
713 1.1 dyoung sn->stats[y][x].perfect_tx_time =
714 1.1 dyoung calc_usecs_unicast_packet(sc, size,
715 1.1 dyoung sn->rates[x].rix,
716 1.1 dyoung 0, 0);
717 1.1 dyoung sn->stats[y][x].average_tx_time = sn->stats[y][x].perfect_tx_time;
718 1.1 dyoung }
719 1.2.2.1 yamt
720 1.2.2.1 yamt /* set the initial rate */
721 1.2.2.1 yamt for (ndx = sn->num_rates-1; ndx > 0; ndx--) {
722 1.2.2.1 yamt if (sn->rates[ndx].rate <= 72) {
723 1.2.2.1 yamt break;
724 1.2.2.1 yamt }
725 1.2.2.1 yamt }
726 1.2.2.1 yamt sn->current_rate[y] = ndx;
727 1.1 dyoung }
728 1.2.2.1 yamt
729 1.2.2.1 yamt DPRINTF(sc, "%s: %s %d rates %d%sMbps (%dus)- %d%sMbps (%dus)\n",
730 1.2.2.1 yamt __func__, ether_sprintf(ni->ni_macaddr),
731 1.2.2.1 yamt sn->num_rates,
732 1.2.2.1 yamt sn->rates[0].rate/2, sn->rates[0].rate % 0x1 ? ".5" : "",
733 1.2.2.1 yamt sn->stats[1][0].perfect_tx_time,
734 1.2.2.1 yamt sn->rates[sn->num_rates-1].rate/2,
735 1.2.2.1 yamt sn->rates[sn->num_rates-1].rate % 0x1 ? ".5" : "",
736 1.2.2.1 yamt sn->stats[1][sn->num_rates-1].perfect_tx_time
737 1.2.2.1 yamt );
738 1.2.2.1 yamt
739 1.2.2.1 yamt ni->ni_txrate = sn->current_rate[0];
740 1.1 dyoung #undef RATE
741 1.1 dyoung }
742 1.1 dyoung
743 1.1 dyoung static void
744 1.1 dyoung rate_cb(void *arg, struct ieee80211_node *ni)
745 1.1 dyoung {
746 1.1 dyoung struct ath_softc *sc = arg;
747 1.1 dyoung
748 1.1 dyoung ath_rate_newassoc(sc, ATH_NODE(ni), 1);
749 1.1 dyoung }
750 1.1 dyoung
751 1.1 dyoung /*
752 1.1 dyoung * Reset the rate control state for each 802.11 state transition.
753 1.1 dyoung */
754 1.1 dyoung void
755 1.1 dyoung ath_rate_newstate(struct ath_softc *sc, enum ieee80211_state state)
756 1.1 dyoung {
757 1.1 dyoung struct ieee80211com *ic = &sc->sc_ic;
758 1.1 dyoung
759 1.1 dyoung if (state == IEEE80211_S_RUN) {
760 1.1 dyoung if (ic->ic_opmode != IEEE80211_M_STA) {
761 1.1 dyoung /*
762 1.1 dyoung * Sync rates for associated stations and neighbors.
763 1.1 dyoung */
764 1.1 dyoung ieee80211_iterate_nodes(&ic->ic_sta, rate_cb, sc);
765 1.1 dyoung }
766 1.1 dyoung ath_rate_newassoc(sc, ATH_NODE(ic->ic_bss), 1);
767 1.1 dyoung }
768 1.1 dyoung }
769 1.1 dyoung
770 1.1 dyoung static void
771 1.1 dyoung ath_rate_sysctlattach(struct ath_softc *sc, struct sample_softc *osc)
772 1.1 dyoung {
773 1.2.2.1 yamt int rc;
774 1.2.2.1 yamt struct sysctllog **log = &sc->sc_sysctllog;
775 1.2.2.1 yamt const struct sysctlnode *cnode, *rnode;
776 1.2.2.1 yamt
777 1.2.2.1 yamt if ((rnode = ath_sysctl_instance(sc->sc_dev.dv_xname, log)) == NULL)
778 1.2.2.1 yamt return;
779 1.1 dyoung
780 1.1 dyoung /* XXX bounds check [0..100] */
781 1.2.2.1 yamt if ((rc = SYSCTL_PFX_INT(osc->ath_, CTLFLAG_READWRITE, smoothing_rate,
782 1.2.2.1 yamt "rate control: retry threshold to credit rate raise (%%)")) != 0)
783 1.2.2.1 yamt goto err;
784 1.2.2.1 yamt
785 1.1 dyoung /* XXX bounds check [2..100] */
786 1.2.2.1 yamt if ((rc = SYSCTL_PFX_INT(osc->ath_, CTLFLAG_READWRITE, sample_rate,
787 1.2.2.1 yamt "rate control: # good periods before raising rate")) != 0)
788 1.2.2.1 yamt goto err;
789 1.2.2.1 yamt
790 1.2.2.1 yamt return;
791 1.2.2.1 yamt err:
792 1.2.2.1 yamt printf("%s: sysctl_createv failed, rc = %d\n", __func__, rc);
793 1.1 dyoung }
794 1.1 dyoung
795 1.1 dyoung struct ath_ratectrl *
796 1.1 dyoung ath_rate_attach(struct ath_softc *sc)
797 1.1 dyoung {
798 1.1 dyoung struct sample_softc *osc;
799 1.1 dyoung
800 1.1 dyoung DPRINTF(sc, "%s:\n", __func__);
801 1.1 dyoung osc = malloc(sizeof(struct sample_softc), M_DEVBUF, M_NOWAIT|M_ZERO);
802 1.1 dyoung if (osc == NULL)
803 1.1 dyoung return NULL;
804 1.1 dyoung osc->arc.arc_space = sizeof(struct sample_node);
805 1.1 dyoung osc->ath_smoothing_rate = 95; /* ewma percentage (out of 100) */
806 1.1 dyoung osc->ath_sample_rate = 10; /* send a different bit-rate 1/X packets */
807 1.1 dyoung ath_rate_sysctlattach(sc, osc);
808 1.1 dyoung return &osc->arc;
809 1.1 dyoung }
810 1.1 dyoung
811 1.1 dyoung void
812 1.1 dyoung ath_rate_detach(struct ath_ratectrl *arc)
813 1.1 dyoung {
814 1.1 dyoung struct sample_softc *osc = (struct sample_softc *) arc;
815 1.1 dyoung
816 1.1 dyoung free(osc, M_DEVBUF);
817 1.1 dyoung }
818