2 +++ b/net/mac80211/rc80211_minstrel.c
5 + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
7 + * This program is free software; you can redistribute it and/or modify
8 + * it under the terms of the GNU General Public License version 2 as
9 + * published by the Free Software Foundation.
11 + * Based on minstrel.c:
12 + * Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
13 + * Sponsored by Indranet Technologies Ltd
15 + * Based on sample.c:
16 + * Copyright (c) 2005 John Bicket
17 + * All rights reserved.
19 + * Redistribution and use in source and binary forms, with or without
20 + * modification, are permitted provided that the following conditions
22 + * 1. Redistributions of source code must retain the above copyright
23 + * notice, this list of conditions and the following disclaimer,
24 + * without modification.
25 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
26 + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
27 + * redistribution must be conditioned upon including a substantially
28 + * similar Disclaimer requirement for further binary redistribution.
29 + * 3. Neither the names of the above-listed copyright holders nor the names
30 + * of any contributors may be used to endorse or promote products derived
31 + * from this software without specific prior written permission.
33 + * Alternatively, this software may be distributed under the terms of the
34 + * GNU General Public License ("GPL") version 2 as published by the Free
35 + * Software Foundation.
38 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
41 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
42 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
43 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
46 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
48 + * THE POSSIBILITY OF SUCH DAMAGES.
50 +#include <linux/netdevice.h>
51 +#include <linux/types.h>
52 +#include <linux/skbuff.h>
53 +#include <linux/debugfs.h>
54 +#include <linux/random.h>
55 +#include <linux/ieee80211.h>
56 +#include <net/mac80211.h>
58 +#include "rc80211_minstrel.h"
60 +#define SAMPLE_COLUMNS 10
61 +#define SAMPLE_TBL(_mi, _idx, _col) \
62 + _mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col]
64 +/* convert mac80211 rate index to local array index */
66 +rix_to_ndx(struct minstrel_sta_info *mi, int rix)
69 + for (i = rix; i >= 0; i--)
70 + if (mi->r[i].rix == rix)
72 + WARN_ON(mi->r[i].rix != rix);
77 +use_low_rate(struct sk_buff *skb)
79 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
80 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
83 + fc = le16_to_cpu(hdr->frame_control);
85 + return ((info->flags & IEEE80211_TX_CTL_NO_ACK) ||
86 + (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
87 + is_multicast_ether_addr(hdr->addr1));
92 +minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
94 + u32 max_tp = 0, index_max_tp = 0, index_max_tp2 = 0;
95 + u32 max_prob = 0, index_max_prob = 0;
100 + mi->stats_update = jiffies;
101 + for (i = 0; i < mi->n_rates; i++) {
102 + struct minstrel_rate *mr = &mi->r[i];
104 + usecs = mr->perfect_tx_time;
108 + /* To avoid rounding issues, probabilities scale from 0 (0%)
109 + * to 18000 (100%) */
110 + if (mr->attempts) {
111 + p = (mr->success * 18000) / mr->attempts;
112 + mr->succ_hist += mr->success;
113 + mr->att_hist += mr->attempts;
115 + p = ((p * (100 - mp->ewma_level)) + (mr->probability *
116 + mp->ewma_level)) / 100;
117 + mr->probability = p;
118 + mr->cur_tp = p * (1000000 / usecs);
121 + mr->last_success = mr->success;
122 + mr->last_attempts = mr->attempts;
126 + /* Sample less often below the 10% chance of success.
127 + * Sample less often above the 95% chance of success. */
128 + if ((mr->probability > 17100) || (mr->probability < 1800)) {
129 + mr->adjusted_retry_count = mr->retry_count >> 1;
130 + if (mr->adjusted_retry_count > 2)
131 + mr->adjusted_retry_count = 2;
133 + mr->adjusted_retry_count = mr->retry_count;
135 + if (!mr->adjusted_retry_count)
136 + mr->adjusted_retry_count = 2;
139 + for (i = 0; i < mi->n_rates; i++) {
140 + struct minstrel_rate *mr = &mi->r[i];
141 + if (max_tp < mr->cur_tp) {
143 + max_tp = mr->cur_tp;
145 + if (max_prob < mr->probability) {
146 + index_max_prob = i;
147 + max_prob = mr->probability;
152 + for (i = 0; i < mi->n_rates; i++) {
153 + struct minstrel_rate *mr = &mi->r[i];
155 + if (i == index_max_tp)
158 + if (max_tp < mr->cur_tp) {
160 + max_tp = mr->cur_tp;
163 + mi->max_tp_rate = index_max_tp;
164 + mi->max_tp_rate2 = index_max_tp2;
165 + mi->max_prob_rate = index_max_prob;
169 +minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
170 + struct ieee80211_sta *sta, void *priv_sta,
171 + struct sk_buff *skb)
173 + struct minstrel_sta_info *mi = priv_sta;
174 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
175 + struct ieee80211_tx_altrate *ar = info->status.retries;
176 + struct minstrel_priv *mp = priv;
180 + if (!info->status.excessive_retries)
183 + if (!mp->has_mrr || (ar[0].rate_idx < 0)) {
184 + ndx = rix_to_ndx(mi, info->tx_rate_idx);
185 + tries = info->status.retry_count + 1;
186 + mi->r[ndx].success += success;
187 + mi->r[ndx].attempts += tries;
191 + for (i = 0; i < 4; i++) {
192 + if (ar[i].rate_idx < 0)
195 + ndx = rix_to_ndx(mi, ar[i].rate_idx);
196 + mi->r[ndx].attempts += ar[i].limit + 1;
198 + if ((i != 3) && (ar[i + 1].rate_idx < 0))
199 + mi->r[ndx].success += success;
202 + if ((info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) && (i >= 0))
203 + mi->sample_count++;
205 + if (mi->sample_deferred > 0)
206 + mi->sample_deferred--;
210 +static inline unsigned int
211 +minstrel_get_retry_count(struct minstrel_rate *mr,
212 + struct ieee80211_tx_info *info)
214 + unsigned int retry = mr->adjusted_retry_count;
216 + if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)
217 + retry = max(2U, min(mr->retry_count_rtscts, retry));
218 + else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)
219 + retry = max(2U, min(mr->retry_count_cts, retry));
225 +minstrel_get_next_sample(struct minstrel_sta_info *mi)
227 + unsigned int sample_ndx;
228 + sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column);
230 + if (mi->sample_idx > (mi->n_rates - 2)) {
231 + mi->sample_idx = 0;
232 + mi->sample_column++;
233 + if (mi->sample_column >= SAMPLE_COLUMNS)
234 + mi->sample_column = 0;
240 +minstrel_get_rate(void *priv, struct ieee80211_supported_band *sband,
241 + struct ieee80211_sta *sta, void *priv_sta,
242 + struct sk_buff *skb, struct rate_selection *sel)
244 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
245 + struct minstrel_sta_info *mi = priv_sta;
246 + struct minstrel_priv *mp = priv;
247 + struct ieee80211_tx_altrate *ar = info->control.retries;
248 + unsigned int ndx, sample_ndx = 0;
250 + bool sample_slower = false;
251 + bool sample = false;
256 + if (!sta || !mi || use_low_rate(skb)) {
257 + sel->rate_idx = rate_lowest_index(sband, sta);
263 + /* mac80211 does not allow mrr for RTS/CTS */
264 + if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) ||
265 + (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
268 + if (time_after(jiffies, mi->stats_update + (mp->update_interval *
270 + minstrel_update_stats(mp, mi);
272 + ndx = mi->max_tp_rate;
275 + sample_rate = mp->lookaround_rate_mrr;
277 + sample_rate = mp->lookaround_rate;
279 + mi->packet_count++;
280 + delta = (mi->packet_count * sample_rate / 100) -
281 + (mi->sample_count + mi->sample_deferred / 2);
283 + /* delta > 0: sampling required */
285 + if (mi->packet_count >= 10000) {
286 + mi->sample_deferred = 0;
287 + mi->sample_count = 0;
288 + mi->packet_count = 0;
289 + } else if (delta > mi->n_rates * 2) {
290 + /* With multi-rate retry, not every planned sample
291 + * attempt actually gets used, due to the way the retry
292 + * chain is set up - [max_tp,sample,prob,lowest] for
293 + * sample_rate < max_tp.
295 + * If there's too much sampling backlog and the link
296 + * starts getting worse, minstrel would start bursting
297 + * out lots of sampling frames, which would result
298 + * in a large throughput loss. */
299 + mi->sample_count += (delta - mi->n_rates * 2);
302 + sample_ndx = minstrel_get_next_sample(mi);
304 + sample_slower = mrr && (mi->r[sample_ndx].perfect_tx_time >
305 + mi->r[ndx].perfect_tx_time);
307 + if (!sample_slower) {
309 + mi->sample_count++;
311 + /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
312 + * packets that have the sampling rate deferred to the
313 + * second MRR stage. Increase the sample counter only
314 + * if the deferred sample rate was actually used.
315 + * Use the sample_deferred counter to make sure that
316 + * the sampling is not done in large bursts */
317 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
318 + mi->sample_deferred++;
321 + sel->rate_idx = mi->r[ndx].rix;
322 + info->control.retry_limit = minstrel_get_retry_count(&mi->r[ndx], info);
325 + ar[0].rate_idx = mi->lowest_rix;
326 + ar[0].limit = mp->max_retry;
327 + ar[1].rate_idx = -1;
334 + mrr_ndx[0] = sample_ndx;
336 + mrr_ndx[0] = mi->max_tp_rate;
338 + mrr_ndx[0] = mi->max_tp_rate2;
340 + mrr_ndx[1] = mi->max_prob_rate;
342 + for (i = 0; i < 3; i++) {
343 + ar[i].rate_idx = mi->r[mrr_ndx[i]].rix;
344 + ar[i].limit = mi->r[mrr_ndx[i]].adjusted_retry_count;
350 +calc_rate_durations(struct minstrel_sta_info *mi, struct ieee80211_local *local,
351 + struct minstrel_rate *d, struct ieee80211_rate *rate)
353 + int erp = !!(rate->flags & IEEE80211_RATE_ERP_G);
355 + d->perfect_tx_time = ieee80211_frame_duration(local, 1200,
356 + rate->bitrate, erp, 1);
357 + d->ack_time = ieee80211_frame_duration(local, 10,
358 + rate->bitrate, erp, 1);
362 +init_sample_table(struct minstrel_sta_info *mi)
364 + unsigned int i, col, new_idx;
365 + unsigned int n_srates = mi->n_rates - 1;
368 + mi->sample_column = 0;
369 + mi->sample_idx = 0;
370 + memset(mi->sample_table, 0, SAMPLE_COLUMNS * mi->n_rates);
372 + for (col = 0; col < SAMPLE_COLUMNS; col++) {
373 + for (i = 0; i < n_srates; i++) {
374 + get_random_bytes(rnd, sizeof(rnd));
375 + new_idx = (i + rnd[i & 7]) % n_srates;
377 + while (SAMPLE_TBL(mi, new_idx, col) != 0)
378 + new_idx = (new_idx + 1) % n_srates;
380 + /* Don't sample the slowest rate (i.e. slowest base
381 + * rate). We must presume that the slowest rate works
382 + * fine, or else other management frames will also be
383 + * failing and the link will break */
384 + SAMPLE_TBL(mi, new_idx, col) = i + 1;
390 +minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
391 + struct ieee80211_sta *sta, void *priv_sta)
393 + struct minstrel_sta_info *mi = priv_sta;
394 + struct minstrel_priv *mp = priv;
395 + struct minstrel_rate *mr_ctl;
396 + unsigned int i, n = 0;
397 + unsigned int t_slot = 9; /* FIXME: get real slot time */
399 + mi->lowest_rix = rate_lowest_index(sband, sta);
400 + mr_ctl = &mi->r[rix_to_ndx(mi, mi->lowest_rix)];
401 + mi->sp_ack_dur = mr_ctl->ack_time;
403 + for (i = 0; i < sband->n_bitrates; i++) {
404 + struct minstrel_rate *mr = &mi->r[n];
405 + unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
406 + unsigned int tx_time_single;
407 + unsigned int cw = mp->cw_min;
409 + if (!rate_supported(sta, sband->band, i))
412 + memset(mr, 0, sizeof(*mr));
415 + mr->bitrate = sband->bitrates[i].bitrate / 5;
416 + calc_rate_durations(mi, hw_to_local(mp->hw), mr,
417 + &sband->bitrates[i]);
419 + /* calculate maximum number of retransmissions before
420 + * fallback (based on maximum segment size) */
421 + mr->retry_count = 1;
422 + mr->retry_count_cts = 1;
423 + mr->retry_count_rtscts = 1;
424 + tx_time = mr->perfect_tx_time + mi->sp_ack_dur;
426 + /* add one retransmission */
427 + tx_time_single = mr->ack_time + mr->perfect_tx_time;
429 + /* contention window */
430 + tx_time_single += t_slot + min(cw, mp->cw_max);
431 + cw = (cw + 1) << 1;
433 + tx_time += tx_time_single;
434 + tx_time_cts += tx_time_single + mi->sp_ack_dur;
435 + tx_time_rtscts += tx_time_single + 2 * mi->sp_ack_dur;
436 + if ((tx_time_cts < mp->segment_size) &&
437 + (mr->retry_count_cts < mp->max_retry))
438 + mr->retry_count_cts++;
439 + if ((tx_time_rtscts < mp->segment_size) &&
440 + (mr->retry_count_rtscts < mp->max_retry))
441 + mr->retry_count_rtscts++;
442 + } while ((tx_time < mp->segment_size) &&
443 + (++mr->retry_count < mp->max_retry));
444 + mr->adjusted_retry_count = mr->retry_count;
447 + for (i = n; i < sband->n_bitrates; i++) {
448 + struct minstrel_rate *mr = &mi->r[i];
453 + mi->stats_update = jiffies;
455 + init_sample_table(mi);
459 +minstrel_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
461 + struct ieee80211_supported_band *sband;
462 + struct minstrel_sta_info *mi;
463 + struct minstrel_priv *mp = priv;
464 + struct ieee80211_hw *hw = mp->hw;
468 + mi = kzalloc(sizeof(struct minstrel_sta_info), gfp);
472 + for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
473 + sband = hw->wiphy->bands[hw->conf.channel->band];
474 + if (sband->n_bitrates > max_rates)
475 + max_rates = sband->n_bitrates;
478 + mi->r = kzalloc(sizeof(struct minstrel_rate) * max_rates, gfp);
482 + mi->sample_table = kmalloc(SAMPLE_COLUMNS * max_rates, gfp);
483 + if (!mi->sample_table)
486 + mi->stats_update = jiffies;
497 +minstrel_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
499 + struct minstrel_sta_info *mi = priv_sta;
501 + kfree(mi->sample_table);
507 +minstrel_clear(void *priv)
512 +minstrel_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
514 + struct minstrel_priv *mp;
516 + mp = kzalloc(sizeof(struct minstrel_priv), GFP_ATOMIC);
520 + /* contention window settings
521 + * Just an approximation. Using the per-queue values would complicate
522 + * the calculations and is probably unnecessary */
526 + /* number of packets (in %) to use for sampling other rates
527 + * sample less often for non-mrr packets, because the overhead
528 + * is much higher than with mrr */
529 + mp->lookaround_rate = 5;
530 + mp->lookaround_rate_mrr = 10;
532 + /* moving average weight for EWMA */
533 + mp->ewma_level = 75;
535 + /* maximum time that the hw is allowed to stay in one MRR segment */
536 + mp->segment_size = 6000;
538 + if (hw->max_altrate_tries > 0)
539 + mp->max_retry = hw->max_altrate_tries;
541 + /* safe default, does not necessarily have to match hw properties */
544 + if (hw->max_altrates >= 3)
545 + mp->has_mrr = true;
548 + mp->update_interval = 100;
554 +minstrel_free(void *priv)
559 +static struct rate_control_ops mac80211_minstrel = {
560 + .name = "minstrel",
561 + .tx_status = minstrel_tx_status,
562 + .get_rate = minstrel_get_rate,
563 + .rate_init = minstrel_rate_init,
564 + .clear = minstrel_clear,
565 + .alloc = minstrel_alloc,
566 + .free = minstrel_free,
567 + .alloc_sta = minstrel_alloc_sta,
568 + .free_sta = minstrel_free_sta,
569 +#ifdef CONFIG_MAC80211_DEBUGFS
570 + .add_sta_debugfs = minstrel_add_sta_debugfs,
571 + .remove_sta_debugfs = minstrel_remove_sta_debugfs,
576 +rc80211_minstrel_init(void)
578 + return ieee80211_rate_control_register(&mac80211_minstrel);
582 +rc80211_minstrel_exit(void)
584 + ieee80211_rate_control_unregister(&mac80211_minstrel);
587 --- a/net/mac80211/Makefile
588 +++ b/net/mac80211/Makefile
590 rc80211_pid-y := rc80211_pid_algo.o
591 rc80211_pid-$(CONFIG_MAC80211_DEBUGFS) += rc80211_pid_debugfs.o
593 +rc80211_minstrel-y := rc80211_minstrel.o
594 +rc80211_minstrel-$(CONFIG_MAC80211_DEBUGFS) += rc80211_minstrel_debugfs.o
596 mac80211-$(CONFIG_MAC80211_RC_PID) += $(rc80211_pid-y)
597 +mac80211-$(CONFIG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
598 --- a/net/mac80211/main.c
599 +++ b/net/mac80211/main.c
600 @@ -1015,6 +1015,10 @@
601 BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
602 IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
604 + ret = rc80211_minstrel_init();
608 ret = rc80211_pid_init();
611 @@ -1027,6 +1031,7 @@
612 static void __exit ieee80211_exit(void)
615 + rc80211_minstrel_exit();
618 * For key todo, it'll be empty by now but the work
619 --- a/net/mac80211/rate.h
620 +++ b/net/mac80211/rate.h
625 +#ifdef CONFIG_MAC80211_RC_MINSTREL
626 +extern int rc80211_minstrel_init(void);
627 +extern void rc80211_minstrel_exit(void);
629 +static inline int rc80211_minstrel_init(void)
633 +static inline void rc80211_minstrel_exit(void)
639 #endif /* IEEE80211_RATE_H */
641 +++ b/net/mac80211/rc80211_minstrel.h
644 + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
646 + * This program is free software; you can redistribute it and/or modify
647 + * it under the terms of the GNU General Public License version 2 as
648 + * published by the Free Software Foundation.
651 +#ifndef __RC_MINSTREL_H
652 +#define __RC_MINSTREL_H
654 +struct minstrel_rate {
658 + unsigned int perfect_tx_time;
659 + unsigned int ack_time;
661 + unsigned int retry_count;
662 + unsigned int retry_count_cts;
663 + unsigned int retry_count_rtscts;
664 + unsigned int adjusted_retry_count;
671 + /* parts per thousand */
675 + /* per-rate throughput */
683 +struct minstrel_sta_info {
684 + unsigned long stats_update;
685 + unsigned int sp_ack_dur;
686 + unsigned int rate_avg;
688 + unsigned int lowest_rix;
690 + unsigned int max_tp_rate;
691 + unsigned int max_tp_rate2;
692 + unsigned int max_prob_rate;
693 + unsigned int packet_count;
694 + unsigned int sample_count;
695 + int sample_deferred;
697 + unsigned int sample_idx;
698 + unsigned int sample_column;
701 + struct minstrel_rate *r;
703 + /* sampling table */
706 +#ifdef CONFIG_MAC80211_DEBUGFS
707 + struct dentry *dbg_stats;
711 +struct minstrel_priv {
712 + struct ieee80211_hw *hw;
714 + unsigned int cw_min;
715 + unsigned int cw_max;
716 + unsigned int max_retry;
717 + unsigned int ewma_level;
718 + unsigned int segment_size;
719 + unsigned int update_interval;
720 + unsigned int lookaround_rate;
721 + unsigned int lookaround_rate_mrr;
724 +void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
725 +void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
729 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
732 + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
734 + * This program is free software; you can redistribute it and/or modify
735 + * it under the terms of the GNU General Public License version 2 as
736 + * published by the Free Software Foundation.
738 + * Based on minstrel.c:
739 + * Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
740 + * Sponsored by Indranet Technologies Ltd
742 + * Based on sample.c:
743 + * Copyright (c) 2005 John Bicket
744 + * All rights reserved.
746 + * Redistribution and use in source and binary forms, with or without
747 + * modification, are permitted provided that the following conditions
749 + * 1. Redistributions of source code must retain the above copyright
750 + * notice, this list of conditions and the following disclaimer,
751 + * without modification.
752 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
753 + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
754 + * redistribution must be conditioned upon including a substantially
755 + * similar Disclaimer requirement for further binary redistribution.
756 + * 3. Neither the names of the above-listed copyright holders nor the names
757 + * of any contributors may be used to endorse or promote products derived
758 + * from this software without specific prior written permission.
760 + * Alternatively, this software may be distributed under the terms of the
761 + * GNU General Public License ("GPL") version 2 as published by the Free
762 + * Software Foundation.
765 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
766 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
767 + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
768 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
769 + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
770 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
771 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
772 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
773 + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
774 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
775 + * THE POSSIBILITY OF SUCH DAMAGES.
777 +#include <linux/netdevice.h>
778 +#include <linux/types.h>
779 +#include <linux/skbuff.h>
780 +#include <linux/debugfs.h>
781 +#include <linux/ieee80211.h>
782 +#include <net/mac80211.h>
783 +#include "rc80211_minstrel.h"
785 +struct minstrel_stats_info {
786 + struct minstrel_sta_info *mi;
792 +minstrel_stats_open(struct inode *inode, struct file *file)
794 + struct minstrel_sta_info *mi = inode->i_private;
795 + struct minstrel_stats_info *ms;
796 + unsigned int i, tp, prob, eprob;
799 + ms = kmalloc(sizeof(*ms), GFP_KERNEL);
803 + file->private_data = ms;
805 + p += sprintf(p, "rate throughput ewma prob this prob "
806 + "this succ/attempt success attempts\n");
807 + for (i = 0; i < mi->n_rates; i++) {
808 + struct minstrel_rate *mr = &mi->r[i];
810 + *(p++) = (i == mi->max_tp_rate) ? 'T' : ' ';
811 + *(p++) = (i == mi->max_tp_rate2) ? 't' : ' ';
812 + *(p++) = (i == mi->max_prob_rate) ? 'P' : ' ';
813 + p += sprintf(p, "%3u%s", mr->bitrate / 2,
814 + (mr->bitrate & 1 ? ".5" : " "));
816 + tp = ((mr->cur_tp * 96) / 18000) >> 10;
817 + prob = mr->cur_prob / 18;
818 + eprob = mr->probability / 18;
820 + p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
821 + "%3u(%3u) %8llu %8llu\n",
823 + eprob / 10, eprob % 10,
824 + prob / 10, prob % 10,
830 + p += sprintf(p, "\nTotal packet count:: ideal %d "
831 + "lookaround %d\n\n",
832 + mi->packet_count - mi->sample_count,
834 + ms->len = p - ms->buf;
840 +minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *o)
842 + struct minstrel_stats_info *ms;
845 + ms = file->private_data;
848 + len = min(len, ms->len);
856 + if (copy_to_user(buf, src, len))
863 +minstrel_stats_release(struct inode *inode, struct file *file)
865 + struct minstrel_stats_info *ms = file->private_data;
872 +static struct file_operations minstrel_stat_fops = {
873 + .owner = THIS_MODULE,
874 + .open = minstrel_stats_open,
875 + .read = minstrel_stats_read,
876 + .release = minstrel_stats_release,
880 +minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
882 + struct minstrel_sta_info *mi = priv_sta;
884 + mi->dbg_stats = debugfs_create_file("rc_stats", S_IRUGO, dir, mi,
885 + &minstrel_stat_fops);
889 +minstrel_remove_sta_debugfs(void *priv, void *priv_sta)
891 + struct minstrel_sta_info *mi = priv_sta;
893 + debugfs_remove(mi->dbg_stats);
895 --- a/net/mac80211/Kconfig
896 +++ b/net/mac80211/Kconfig
898 mac80211 that uses a PID controller to select the TX
901 +config MAC80211_RC_MINSTREL
904 + This option enables the 'minstrel' TX rate control algorithm
907 prompt "Default rate control algorithm"
908 default MAC80211_RC_DEFAULT_PID
910 default rate control algorithm. You should choose
911 this unless you know what you are doing.
913 +config MAC80211_RC_DEFAULT_MINSTREL
915 + depends on MAC80211_RC_MINSTREL
917 + Select Minstrel as the default rate control algorithm.
922 config MAC80211_RC_DEFAULT
924 default "pid" if MAC80211_RC_DEFAULT_PID
925 + default "minstrel" if MAC80211_RC_DEFAULT_MINSTREL