blob: 96ee595ac1a816e45a6425900f6ecea78db857f8 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Felix Fietkau <nbd@nbd.name>
2Date: Sat, 26 Dec 2020 14:23:47 +0100
3Subject: [PATCH] mac80211: remove legacy minstrel rate control
4
5Now that minstrel_ht supports legacy rates, it is no longer needed
6
7Signed-off-by: Felix Fietkau <nbd@nbd.name>
8---
9 delete mode 100644 net/mac80211/rc80211_minstrel.c
10 delete mode 100644 net/mac80211/rc80211_minstrel.h
11 delete mode 100644 net/mac80211/rc80211_minstrel_debugfs.c
12
13--- a/net/mac80211/Makefile
14+++ b/net/mac80211/Makefile
15@@ -55,11 +55,9 @@ mac80211-$(CONFIG_PM) += pm.o
16 CFLAGS_trace.o := -I$(src)
17
18 rc80211_minstrel-y := \
19- rc80211_minstrel.o \
20 rc80211_minstrel_ht.o
21
22 rc80211_minstrel-$(CPTCFG_MAC80211_DEBUGFS) += \
23- rc80211_minstrel_debugfs.o \
24 rc80211_minstrel_ht_debugfs.o
25
26 mac80211-$(CPTCFG_MAC80211_RC_MINSTREL) += $(rc80211_minstrel-y)
27--- a/net/mac80211/rc80211_minstrel.c
28+++ /dev/null
29@@ -1,574 +0,0 @@
30-/*
31- * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
32- *
33- * This program is free software; you can redistribute it and/or modify
34- * it under the terms of the GNU General Public License version 2 as
35- * published by the Free Software Foundation.
36- *
37- * Based on minstrel.c:
38- * Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
39- * Sponsored by Indranet Technologies Ltd
40- *
41- * Based on sample.c:
42- * Copyright (c) 2005 John Bicket
43- * All rights reserved.
44- *
45- * Redistribution and use in source and binary forms, with or without
46- * modification, are permitted provided that the following conditions
47- * are met:
48- * 1. Redistributions of source code must retain the above copyright
49- * notice, this list of conditions and the following disclaimer,
50- * without modification.
51- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
52- * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
53- * redistribution must be conditioned upon including a substantially
54- * similar Disclaimer requirement for further binary redistribution.
55- * 3. Neither the names of the above-listed copyright holders nor the names
56- * of any contributors may be used to endorse or promote products derived
57- * from this software without specific prior written permission.
58- *
59- * Alternatively, this software may be distributed under the terms of the
60- * GNU General Public License ("GPL") version 2 as published by the Free
61- * Software Foundation.
62- *
63- * NO WARRANTY
64- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
65- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
66- * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
67- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
68- * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
69- * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
70- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
71- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
72- * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
73- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
74- * THE POSSIBILITY OF SUCH DAMAGES.
75- */
76-#include <linux/netdevice.h>
77-#include <linux/types.h>
78-#include <linux/skbuff.h>
79-#include <linux/debugfs.h>
80-#include <linux/random.h>
81-#include <linux/ieee80211.h>
82-#include <linux/slab.h>
83-#include <net/mac80211.h>
84-#include "rate.h"
85-#include "rc80211_minstrel.h"
86-
87-#define SAMPLE_TBL(_mi, _idx, _col) \
88- _mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col]
89-
90-/* convert mac80211 rate index to local array index */
91-static inline int
92-rix_to_ndx(struct minstrel_sta_info *mi, int rix)
93-{
94- int i = rix;
95- for (i = rix; i >= 0; i--)
96- if (mi->r[i].rix == rix)
97- break;
98- return i;
99-}
100-
101-/* return current EMWA throughput */
102-int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_avg)
103-{
104- int usecs;
105-
106- usecs = mr->perfect_tx_time;
107- if (!usecs)
108- usecs = 1000000;
109-
110- /* reset thr. below 10% success */
111- if (mr->stats.prob_avg < MINSTREL_FRAC(10, 100))
112- return 0;
113-
114- if (prob_avg > MINSTREL_FRAC(90, 100))
115- return MINSTREL_TRUNC(100000 * (MINSTREL_FRAC(90, 100) / usecs));
116- else
117- return MINSTREL_TRUNC(100000 * (prob_avg / usecs));
118-}
119-
120-/* find & sort topmost throughput rates */
121-static inline void
122-minstrel_sort_best_tp_rates(struct minstrel_sta_info *mi, int i, u8 *tp_list)
123-{
124- int j;
125- struct minstrel_rate_stats *tmp_mrs;
126- struct minstrel_rate_stats *cur_mrs = &mi->r[i].stats;
127-
128- for (j = MAX_THR_RATES; j > 0; --j) {
129- tmp_mrs = &mi->r[tp_list[j - 1]].stats;
130- if (minstrel_get_tp_avg(&mi->r[i], cur_mrs->prob_avg) <=
131- minstrel_get_tp_avg(&mi->r[tp_list[j - 1]], tmp_mrs->prob_avg))
132- break;
133- }
134-
135- if (j < MAX_THR_RATES - 1)
136- memmove(&tp_list[j + 1], &tp_list[j], MAX_THR_RATES - (j + 1));
137- if (j < MAX_THR_RATES)
138- tp_list[j] = i;
139-}
140-
141-static void
142-minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
143- int offset, int idx)
144-{
145- struct minstrel_rate *r = &mi->r[idx];
146-
147- ratetbl->rate[offset].idx = r->rix;
148- ratetbl->rate[offset].count = r->adjusted_retry_count;
149- ratetbl->rate[offset].count_cts = r->retry_count_cts;
150- ratetbl->rate[offset].count_rts = r->stats.retry_count_rtscts;
151-}
152-
153-static void
154-minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
155-{
156- struct ieee80211_sta_rates *ratetbl;
157- int i = 0;
158-
159- ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
160- if (!ratetbl)
161- return;
162-
163- /* Start with max_tp_rate */
164- minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
165-
166- if (mp->hw->max_rates >= 3) {
167- /* At least 3 tx rates supported, use max_tp_rate2 next */
168- minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
169- }
170-
171- if (mp->hw->max_rates >= 2) {
172- /* At least 2 tx rates supported, use max_prob_rate next */
173- minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
174- }
175-
176- /* Use lowest rate last */
177- ratetbl->rate[i].idx = mi->lowest_rix;
178- ratetbl->rate[i].count = mp->max_retry;
179- ratetbl->rate[i].count_cts = mp->max_retry;
180- ratetbl->rate[i].count_rts = mp->max_retry;
181-
182- rate_control_set_rates(mp->hw, mi->sta, ratetbl);
183-}
184-
185-/*
186-* Recalculate statistics and counters of a given rate
187-*/
188-void
189-minstrel_calc_rate_stats(struct minstrel_priv *mp,
190- struct minstrel_rate_stats *mrs)
191-{
192- unsigned int cur_prob;
193-
194- if (unlikely(mrs->attempts > 0)) {
195- mrs->sample_skipped = 0;
196- cur_prob = MINSTREL_FRAC(mrs->success, mrs->attempts);
197- if (mp->new_avg) {
198- minstrel_filter_avg_add(&mrs->prob_avg,
199- &mrs->prob_avg_1, cur_prob);
200- } else if (unlikely(!mrs->att_hist)) {
201- mrs->prob_avg = cur_prob;
202- } else {
203- /*update exponential weighted moving avarage */
204- mrs->prob_avg = minstrel_ewma(mrs->prob_avg,
205- cur_prob,
206- EWMA_LEVEL);
207- }
208- mrs->att_hist += mrs->attempts;
209- mrs->succ_hist += mrs->success;
210- } else {
211- mrs->sample_skipped++;
212- }
213-
214- mrs->last_success = mrs->success;
215- mrs->last_attempts = mrs->attempts;
216- mrs->success = 0;
217- mrs->attempts = 0;
218-}
219-
220-static void
221-minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
222-{
223- u8 tmp_tp_rate[MAX_THR_RATES];
224- u8 tmp_prob_rate = 0;
225- int i, tmp_cur_tp, tmp_prob_tp;
226-
227- for (i = 0; i < MAX_THR_RATES; i++)
228- tmp_tp_rate[i] = 0;
229-
230- for (i = 0; i < mi->n_rates; i++) {
231- struct minstrel_rate *mr = &mi->r[i];
232- struct minstrel_rate_stats *mrs = &mi->r[i].stats;
233- struct minstrel_rate_stats *tmp_mrs = &mi->r[tmp_prob_rate].stats;
234-
235- /* Update statistics of success probability per rate */
236- minstrel_calc_rate_stats(mp, mrs);
237-
238- /* Sample less often below the 10% chance of success.
239- * Sample less often above the 95% chance of success. */
240- if (mrs->prob_avg > MINSTREL_FRAC(95, 100) ||
241- mrs->prob_avg < MINSTREL_FRAC(10, 100)) {
242- mr->adjusted_retry_count = mrs->retry_count >> 1;
243- if (mr->adjusted_retry_count > 2)
244- mr->adjusted_retry_count = 2;
245- mr->sample_limit = 4;
246- } else {
247- mr->sample_limit = -1;
248- mr->adjusted_retry_count = mrs->retry_count;
249- }
250- if (!mr->adjusted_retry_count)
251- mr->adjusted_retry_count = 2;
252-
253- minstrel_sort_best_tp_rates(mi, i, tmp_tp_rate);
254-
255- /* To determine the most robust rate (max_prob_rate) used at
256- * 3rd mmr stage we distinct between two cases:
257- * (1) if any success probabilitiy >= 95%, out of those rates
258- * choose the maximum throughput rate as max_prob_rate
259- * (2) if all success probabilities < 95%, the rate with
260- * highest success probability is chosen as max_prob_rate */
261- if (mrs->prob_avg >= MINSTREL_FRAC(95, 100)) {
262- tmp_cur_tp = minstrel_get_tp_avg(mr, mrs->prob_avg);
263- tmp_prob_tp = minstrel_get_tp_avg(&mi->r[tmp_prob_rate],
264- tmp_mrs->prob_avg);
265- if (tmp_cur_tp >= tmp_prob_tp)
266- tmp_prob_rate = i;
267- } else {
268- if (mrs->prob_avg >= tmp_mrs->prob_avg)
269- tmp_prob_rate = i;
270- }
271- }
272-
273- /* Assign the new rate set */
274- memcpy(mi->max_tp_rate, tmp_tp_rate, sizeof(mi->max_tp_rate));
275- mi->max_prob_rate = tmp_prob_rate;
276-
277-#ifdef CPTCFG_MAC80211_DEBUGFS
278- /* use fixed index if set */
279- if (mp->fixed_rate_idx != -1) {
280- mi->max_tp_rate[0] = mp->fixed_rate_idx;
281- mi->max_tp_rate[1] = mp->fixed_rate_idx;
282- mi->max_prob_rate = mp->fixed_rate_idx;
283- }
284-#endif
285-
286- /* Reset update timer */
287- mi->last_stats_update = jiffies;
288-
289- minstrel_update_rates(mp, mi);
290-}
291-
292-static void
293-minstrel_tx_status(void *priv, struct ieee80211_supported_band *sband,
294- void *priv_sta, struct ieee80211_tx_status *st)
295-{
296- struct ieee80211_tx_info *info = st->info;
297- struct minstrel_priv *mp = priv;
298- struct minstrel_sta_info *mi = priv_sta;
299- struct ieee80211_tx_rate *ar = info->status.rates;
300- int i, ndx;
301- int success;
302-
303- success = !!(info->flags & IEEE80211_TX_STAT_ACK);
304-
305- for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
306- if (ar[i].idx < 0 || !ar[i].count)
307- break;
308-
309- ndx = rix_to_ndx(mi, ar[i].idx);
310- if (ndx < 0)
311- continue;
312-
313- mi->r[ndx].stats.attempts += ar[i].count;
314-
315- if ((i != IEEE80211_TX_MAX_RATES - 1) && (ar[i + 1].idx < 0))
316- mi->r[ndx].stats.success += success;
317- }
318-
319- if (time_after(jiffies, mi->last_stats_update +
320- mp->update_interval / (mp->new_avg ? 2 : 1)))
321- minstrel_update_stats(mp, mi);
322-}
323-
324-
325-static inline unsigned int
326-minstrel_get_retry_count(struct minstrel_rate *mr,
327- struct ieee80211_tx_info *info)
328-{
329- u8 retry = mr->adjusted_retry_count;
330-
331- if (info->control.use_rts)
332- retry = max_t(u8, 2, min(mr->stats.retry_count_rtscts, retry));
333- else if (info->control.use_cts_prot)
334- retry = max_t(u8, 2, min(mr->retry_count_cts, retry));
335- return retry;
336-}
337-
338-
339-static int
340-minstrel_get_next_sample(struct minstrel_sta_info *mi)
341-{
342- unsigned int sample_ndx;
343- sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column);
344- mi->sample_row++;
345- if ((int) mi->sample_row >= mi->n_rates) {
346- mi->sample_row = 0;
347- mi->sample_column++;
348- if (mi->sample_column >= SAMPLE_COLUMNS)
349- mi->sample_column = 0;
350- }
351- return sample_ndx;
352-}
353-
354-static void
355-minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
356- void *priv_sta, struct ieee80211_tx_rate_control *txrc)
357-{
358- struct sk_buff *skb = txrc->skb;
359- struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
360- struct minstrel_sta_info *mi = priv_sta;
361- struct minstrel_priv *mp = priv;
362- struct ieee80211_tx_rate *rate = &info->control.rates[0];
363- struct minstrel_rate *msr, *mr;
364- unsigned int ndx;
365- bool mrr_capable;
366- bool prev_sample;
367- int delta;
368- int sampling_ratio;
369-
370- /* check multi-rate-retry capabilities & adjust lookaround_rate */
371- mrr_capable = mp->has_mrr &&
372- !txrc->rts &&
373- !txrc->bss_conf->use_cts_prot;
374- if (mrr_capable)
375- sampling_ratio = mp->lookaround_rate_mrr;
376- else
377- sampling_ratio = mp->lookaround_rate;
378-
379- /* increase sum packet counter */
380- mi->total_packets++;
381-
382-#ifdef CPTCFG_MAC80211_DEBUGFS
383- if (mp->fixed_rate_idx != -1)
384- return;
385-#endif
386-
387- /* Don't use EAPOL frames for sampling on non-mrr hw */
388- if (mp->hw->max_rates == 1 &&
389- (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO))
390- return;
391-
392- delta = (mi->total_packets * sampling_ratio / 100) -
393- mi->sample_packets;
394-
395- /* delta < 0: no sampling required */
396- prev_sample = mi->prev_sample;
397- mi->prev_sample = false;
398- if (delta < 0 || (!mrr_capable && prev_sample))
399- return;
400-
401- if (mi->total_packets >= 10000) {
402- mi->sample_packets = 0;
403- mi->total_packets = 0;
404- } else if (delta > mi->n_rates * 2) {
405- /* With multi-rate retry, not every planned sample
406- * attempt actually gets used, due to the way the retry
407- * chain is set up - [max_tp,sample,prob,lowest] for
408- * sample_rate < max_tp.
409- *
410- * If there's too much sampling backlog and the link
411- * starts getting worse, minstrel would start bursting
412- * out lots of sampling frames, which would result
413- * in a large throughput loss. */
414- mi->sample_packets += (delta - mi->n_rates * 2);
415- }
416-
417- /* get next random rate sample */
418- ndx = minstrel_get_next_sample(mi);
419- msr = &mi->r[ndx];
420- mr = &mi->r[mi->max_tp_rate[0]];
421-
422- /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
423- * rate sampling method should be used.
424- * Respect such rates that are not sampled for 20 interations.
425- */
426- if (msr->perfect_tx_time < mr->perfect_tx_time ||
427- msr->stats.sample_skipped >= 20) {
428- if (!msr->sample_limit)
429- return;
430-
431- mi->sample_packets++;
432- if (msr->sample_limit > 0)
433- msr->sample_limit--;
434- }
435-
436- /* If we're not using MRR and the sampling rate already
437- * has a probability of >95%, we shouldn't be attempting
438- * to use it, as this only wastes precious airtime */
439- if (!mrr_capable &&
440- (mi->r[ndx].stats.prob_avg > MINSTREL_FRAC(95, 100)))
441- return;
442-
443- mi->prev_sample = true;
444-
445- rate->idx = mi->r[ndx].rix;
446- rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
447- info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
448-}
449-
450-
451-static void
452-calc_rate_durations(enum nl80211_band band,
453- struct minstrel_rate *d,
454- struct ieee80211_rate *rate,
455- struct cfg80211_chan_def *chandef)
456-{
457- int erp = !!(rate->flags & IEEE80211_RATE_ERP_G);
458- int shift = ieee80211_chandef_get_shift(chandef);
459-
460- d->perfect_tx_time = ieee80211_frame_duration(band, 1200,
461- DIV_ROUND_UP(rate->bitrate, 1 << shift), erp, 1,
462- shift);
463- d->ack_time = ieee80211_frame_duration(band, 10,
464- DIV_ROUND_UP(rate->bitrate, 1 << shift), erp, 1,
465- shift);
466-}
467-
468-static void
469-init_sample_table(struct minstrel_sta_info *mi)
470-{
471- unsigned int i, col, new_idx;
472- u8 rnd[8];
473-
474- mi->sample_column = 0;
475- mi->sample_row = 0;
476- memset(mi->sample_table, 0xff, SAMPLE_COLUMNS * mi->n_rates);
477-
478- for (col = 0; col < SAMPLE_COLUMNS; col++) {
479- prandom_bytes(rnd, sizeof(rnd));
480- for (i = 0; i < mi->n_rates; i++) {
481- new_idx = (i + rnd[i & 7]) % mi->n_rates;
482- while (SAMPLE_TBL(mi, new_idx, col) != 0xff)
483- new_idx = (new_idx + 1) % mi->n_rates;
484-
485- SAMPLE_TBL(mi, new_idx, col) = i;
486- }
487- }
488-}
489-
490-static void
491-minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
492- struct cfg80211_chan_def *chandef,
493- struct ieee80211_sta *sta, void *priv_sta)
494-{
495- struct minstrel_sta_info *mi = priv_sta;
496- struct minstrel_priv *mp = priv;
497- struct ieee80211_rate *ctl_rate;
498- unsigned int i, n = 0;
499- unsigned int t_slot = 9; /* FIXME: get real slot time */
500- u32 rate_flags;
501-
502- mi->sta = sta;
503- mi->lowest_rix = rate_lowest_index(sband, sta);
504- ctl_rate = &sband->bitrates[mi->lowest_rix];
505- mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
506- ctl_rate->bitrate,
507- !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1,
508- ieee80211_chandef_get_shift(chandef));
509-
510- rate_flags = ieee80211_chandef_rate_flags(&mp->hw->conf.chandef);
511- memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
512- mi->max_prob_rate = 0;
513-
514- for (i = 0; i < sband->n_bitrates; i++) {
515- struct minstrel_rate *mr = &mi->r[n];
516- struct minstrel_rate_stats *mrs = &mi->r[n].stats;
517- unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
518- unsigned int tx_time_single;
519- unsigned int cw = mp->cw_min;
520- int shift;
521-
522- if (!rate_supported(sta, sband->band, i))
523- continue;
524- if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
525- continue;
526-
527- n++;
528- memset(mr, 0, sizeof(*mr));
529- memset(mrs, 0, sizeof(*mrs));
530-
531- mr->rix = i;
532- shift = ieee80211_chandef_get_shift(chandef);
533- mr->bitrate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
534- (1 << shift) * 5);
535- calc_rate_durations(sband->band, mr, &sband->bitrates[i],
536- chandef);
537-
538- /* calculate maximum number of retransmissions before
539- * fallback (based on maximum segment size) */
540- mr->sample_limit = -1;
541- mrs->retry_count = 1;
542- mr->retry_count_cts = 1;
543- mrs->retry_count_rtscts = 1;
544- tx_time = mr->perfect_tx_time + mi->sp_ack_dur;
545- do {
546- /* add one retransmission */
547- tx_time_single = mr->ack_time + mr->perfect_tx_time;
548-
549- /* contention window */
550- tx_time_single += (t_slot * cw) >> 1;
551- cw = min((cw << 1) | 1, mp->cw_max);
552-
553- tx_time += tx_time_single;
554- tx_time_cts += tx_time_single + mi->sp_ack_dur;
555- tx_time_rtscts += tx_time_single + 2 * mi->sp_ack_dur;
556- if ((tx_time_cts < mp->segment_size) &&
557- (mr->retry_count_cts < mp->max_retry))
558- mr->retry_count_cts++;
559- if ((tx_time_rtscts < mp->segment_size) &&
560- (mrs->retry_count_rtscts < mp->max_retry))
561- mrs->retry_count_rtscts++;
562- } while ((tx_time < mp->segment_size) &&
563- (++mr->stats.retry_count < mp->max_retry));
564- mr->adjusted_retry_count = mrs->retry_count;
565- if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
566- mr->retry_count_cts = mrs->retry_count;
567- }
568-
569- for (i = n; i < sband->n_bitrates; i++) {
570- struct minstrel_rate *mr = &mi->r[i];
571- mr->rix = -1;
572- }
573-
574- mi->n_rates = n;
575- mi->last_stats_update = jiffies;
576-
577- init_sample_table(mi);
578- minstrel_update_rates(mp, mi);
579-}
580-
581-static u32 minstrel_get_expected_throughput(void *priv_sta)
582-{
583- struct minstrel_sta_info *mi = priv_sta;
584- struct minstrel_rate_stats *tmp_mrs;
585- int idx = mi->max_tp_rate[0];
586- int tmp_cur_tp;
587-
588- /* convert pkt per sec in kbps (1200 is the average pkt size used for
589- * computing cur_tp
590- */
591- tmp_mrs = &mi->r[idx].stats;
592- tmp_cur_tp = minstrel_get_tp_avg(&mi->r[idx], tmp_mrs->prob_avg) * 10;
593- tmp_cur_tp = tmp_cur_tp * 1200 * 8 / 1024;
594-
595- return tmp_cur_tp;
596-}
597-
598-const struct rate_control_ops mac80211_minstrel = {
599- .tx_status_ext = minstrel_tx_status,
600- .get_rate = minstrel_get_rate,
601- .rate_init = minstrel_rate_init,
602- .get_expected_throughput = minstrel_get_expected_throughput,
603-};
604--- a/net/mac80211/rc80211_minstrel.h
605+++ /dev/null
606@@ -1,185 +0,0 @@
607-/* SPDX-License-Identifier: GPL-2.0-only */
608-/*
609- * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
610- */
611-
612-#ifndef __RC_MINSTREL_H
613-#define __RC_MINSTREL_H
614-
615-#define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
616-#define EWMA_DIV 128
617-#define SAMPLE_COLUMNS 10 /* number of columns in sample table */
618-
619-/* scaled fraction values */
620-#define MINSTREL_SCALE 12
621-#define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
622-#define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
623-
624-/* number of highest throughput rates to consider*/
625-#define MAX_THR_RATES 4
626-
627-/*
628- * Coefficients for moving average with noise filter (period=16),
629- * scaled by 10 bits
630- *
631- * a1 = exp(-pi * sqrt(2) / period)
632- * coeff2 = 2 * a1 * cos(sqrt(2) * 2 * pi / period)
633- * coeff3 = -sqr(a1)
634- * coeff1 = 1 - coeff2 - coeff3
635- */
636-#define MINSTREL_AVG_COEFF1 (MINSTREL_FRAC(1, 1) - \
637- MINSTREL_AVG_COEFF2 - \
638- MINSTREL_AVG_COEFF3)
639-#define MINSTREL_AVG_COEFF2 0x00001499
640-#define MINSTREL_AVG_COEFF3 -0x0000092e
641-
642-/*
643- * Perform EWMA (Exponentially Weighted Moving Average) calculation
644- */
645-static inline int
646-minstrel_ewma(int old, int new, int weight)
647-{
648- int diff, incr;
649-
650- diff = new - old;
651- incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
652-
653- return old + incr;
654-}
655-
656-static inline int minstrel_filter_avg_add(u16 *prev_1, u16 *prev_2, s32 in)
657-{
658- s32 out_1 = *prev_1;
659- s32 out_2 = *prev_2;
660- s32 val;
661-
662- if (!in)
663- in += 1;
664-
665- if (!out_1) {
666- val = out_1 = in;
667- goto out;
668- }
669-
670- val = MINSTREL_AVG_COEFF1 * in;
671- val += MINSTREL_AVG_COEFF2 * out_1;
672- val += MINSTREL_AVG_COEFF3 * out_2;
673- val >>= MINSTREL_SCALE;
674-
675- if (val > 1 << MINSTREL_SCALE)
676- val = 1 << MINSTREL_SCALE;
677- if (val < 0)
678- val = 1;
679-
680-out:
681- *prev_2 = out_1;
682- *prev_1 = val;
683-
684- return val;
685-}
686-
687-struct minstrel_rate_stats {
688- /* current / last sampling period attempts/success counters */
689- u16 attempts, last_attempts;
690- u16 success, last_success;
691-
692- /* total attempts/success counters */
693- u32 att_hist, succ_hist;
694-
695- /* prob_avg - moving average of prob */
696- u16 prob_avg;
697- u16 prob_avg_1;
698-
699- /* maximum retry counts */
700- u8 retry_count;
701- u8 retry_count_rtscts;
702-
703- u8 sample_skipped;
704- bool retry_updated;
705-};
706-
707-struct minstrel_rate {
708- int bitrate;
709-
710- s8 rix;
711- u8 retry_count_cts;
712- u8 adjusted_retry_count;
713-
714- unsigned int perfect_tx_time;
715- unsigned int ack_time;
716-
717- int sample_limit;
718-
719- struct minstrel_rate_stats stats;
720-};
721-
722-struct minstrel_sta_info {
723- struct ieee80211_sta *sta;
724-
725- unsigned long last_stats_update;
726- unsigned int sp_ack_dur;
727- unsigned int rate_avg;
728-
729- unsigned int lowest_rix;
730-
731- u8 max_tp_rate[MAX_THR_RATES];
732- u8 max_prob_rate;
733- unsigned int total_packets;
734- unsigned int sample_packets;
735-
736- unsigned int sample_row;
737- unsigned int sample_column;
738-
739- int n_rates;
740- struct minstrel_rate *r;
741- bool prev_sample;
742-
743- /* sampling table */
744- u8 *sample_table;
745-};
746-
747-struct minstrel_priv {
748- struct ieee80211_hw *hw;
749- bool has_mrr;
750- bool new_avg;
751- u32 sample_switch;
752- unsigned int cw_min;
753- unsigned int cw_max;
754- unsigned int max_retry;
755- unsigned int segment_size;
756- unsigned int update_interval;
757- unsigned int lookaround_rate;
758- unsigned int lookaround_rate_mrr;
759-
760- u8 cck_rates[4];
761- u8 ofdm_rates[NUM_NL80211_BANDS][8];
762-
763-#ifdef CPTCFG_MAC80211_DEBUGFS
764- /*
765- * enable fixed rate processing per RC
766- * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
767- * - write -1 to enable RC processing again
768- * - setting will be applied on next update
769- */
770- u32 fixed_rate_idx;
771-#endif
772-};
773-
774-struct minstrel_debugfs_info {
775- size_t len;
776- char buf[];
777-};
778-
779-extern const struct rate_control_ops mac80211_minstrel;
780-void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
781-
782-/* Recalculate success probabilities and counters for a given rate using EWMA */
783-void minstrel_calc_rate_stats(struct minstrel_priv *mp,
784- struct minstrel_rate_stats *mrs);
785-int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_avg);
786-
787-/* debugfs */
788-int minstrel_stats_open(struct inode *inode, struct file *file);
789-int minstrel_stats_csv_open(struct inode *inode, struct file *file);
790-
791-#endif
792--- a/net/mac80211/rc80211_minstrel_debugfs.c
793+++ /dev/null
794@@ -1,172 +0,0 @@
795-/*
796- * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
797- *
798- * This program is free software; you can redistribute it and/or modify
799- * it under the terms of the GNU General Public License version 2 as
800- * published by the Free Software Foundation.
801- *
802- * Based on minstrel.c:
803- * Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
804- * Sponsored by Indranet Technologies Ltd
805- *
806- * Based on sample.c:
807- * Copyright (c) 2005 John Bicket
808- * All rights reserved.
809- *
810- * Redistribution and use in source and binary forms, with or without
811- * modification, are permitted provided that the following conditions
812- * are met:
813- * 1. Redistributions of source code must retain the above copyright
814- * notice, this list of conditions and the following disclaimer,
815- * without modification.
816- * 2. Redistributions in binary form must reproduce at minimum a disclaimer
817- * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
818- * redistribution must be conditioned upon including a substantially
819- * similar Disclaimer requirement for further binary redistribution.
820- * 3. Neither the names of the above-listed copyright holders nor the names
821- * of any contributors may be used to endorse or promote products derived
822- * from this software without specific prior written permission.
823- *
824- * Alternatively, this software may be distributed under the terms of the
825- * GNU General Public License ("GPL") version 2 as published by the Free
826- * Software Foundation.
827- *
828- * NO WARRANTY
829- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
830- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
831- * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
832- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
833- * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
834- * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
835- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
836- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
837- * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
838- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
839- * THE POSSIBILITY OF SUCH DAMAGES.
840- */
841-#include <linux/netdevice.h>
842-#include <linux/types.h>
843-#include <linux/skbuff.h>
844-#include <linux/debugfs.h>
845-#include <linux/ieee80211.h>
846-#include <linux/slab.h>
847-#include <linux/export.h>
848-#include <net/mac80211.h>
849-#include "rc80211_minstrel.h"
850-
851-int
852-minstrel_stats_open(struct inode *inode, struct file *file)
853-{
854- struct minstrel_sta_info *mi = inode->i_private;
855- struct minstrel_debugfs_info *ms;
856- unsigned int i, tp_max, tp_avg, eprob;
857- char *p;
858-
859- ms = kmalloc(2048, GFP_KERNEL);
860- if (!ms)
861- return -ENOMEM;
862-
863- file->private_data = ms;
864- p = ms->buf;
865- p += sprintf(p, "\n");
866- p += sprintf(p,
867- "best __________rate_________ ____statistics___ ____last_____ ______sum-of________\n");
868- p += sprintf(p,
869- "rate [name idx airtime max_tp] [avg(tp) avg(prob)] [retry|suc|att] [#success | #attempts]\n");
870-
871- for (i = 0; i < mi->n_rates; i++) {
872- struct minstrel_rate *mr = &mi->r[i];
873- struct minstrel_rate_stats *mrs = &mi->r[i].stats;
874-
875- *(p++) = (i == mi->max_tp_rate[0]) ? 'A' : ' ';
876- *(p++) = (i == mi->max_tp_rate[1]) ? 'B' : ' ';
877- *(p++) = (i == mi->max_tp_rate[2]) ? 'C' : ' ';
878- *(p++) = (i == mi->max_tp_rate[3]) ? 'D' : ' ';
879- *(p++) = (i == mi->max_prob_rate) ? 'P' : ' ';
880-
881- p += sprintf(p, " %3u%s ", mr->bitrate / 2,
882- (mr->bitrate & 1 ? ".5" : " "));
883- p += sprintf(p, "%3u ", i);
884- p += sprintf(p, "%6u ", mr->perfect_tx_time);
885-
886- tp_max = minstrel_get_tp_avg(mr, MINSTREL_FRAC(100,100));
887- tp_avg = minstrel_get_tp_avg(mr, mrs->prob_avg);
888- eprob = MINSTREL_TRUNC(mrs->prob_avg * 1000);
889-
890- p += sprintf(p, "%4u.%1u %4u.%1u %3u.%1u"
891- " %3u %3u %-3u "
892- "%9llu %-9llu\n",
893- tp_max / 10, tp_max % 10,
894- tp_avg / 10, tp_avg % 10,
895- eprob / 10, eprob % 10,
896- mrs->retry_count,
897- mrs->last_success,
898- mrs->last_attempts,
899- (unsigned long long)mrs->succ_hist,
900- (unsigned long long)mrs->att_hist);
901- }
902- p += sprintf(p, "\nTotal packet count:: ideal %d "
903- "lookaround %d\n\n",
904- mi->total_packets - mi->sample_packets,
905- mi->sample_packets);
906- ms->len = p - ms->buf;
907-
908- WARN_ON(ms->len + sizeof(*ms) > 2048);
909-
910- return 0;
911-}
912-
913-int
914-minstrel_stats_csv_open(struct inode *inode, struct file *file)
915-{
916- struct minstrel_sta_info *mi = inode->i_private;
917- struct minstrel_debugfs_info *ms;
918- unsigned int i, tp_max, tp_avg, eprob;
919- char *p;
920-
921- ms = kmalloc(2048, GFP_KERNEL);
922- if (!ms)
923- return -ENOMEM;
924-
925- file->private_data = ms;
926- p = ms->buf;
927-
928- for (i = 0; i < mi->n_rates; i++) {
929- struct minstrel_rate *mr = &mi->r[i];
930- struct minstrel_rate_stats *mrs = &mi->r[i].stats;
931-
932- p += sprintf(p, "%s" ,((i == mi->max_tp_rate[0]) ? "A" : ""));
933- p += sprintf(p, "%s" ,((i == mi->max_tp_rate[1]) ? "B" : ""));
934- p += sprintf(p, "%s" ,((i == mi->max_tp_rate[2]) ? "C" : ""));
935- p += sprintf(p, "%s" ,((i == mi->max_tp_rate[3]) ? "D" : ""));
936- p += sprintf(p, "%s" ,((i == mi->max_prob_rate) ? "P" : ""));
937-
938- p += sprintf(p, ",%u%s", mr->bitrate / 2,
939- (mr->bitrate & 1 ? ".5," : ","));
940- p += sprintf(p, "%u,", i);
941- p += sprintf(p, "%u,",mr->perfect_tx_time);
942-
943- tp_max = minstrel_get_tp_avg(mr, MINSTREL_FRAC(100,100));
944- tp_avg = minstrel_get_tp_avg(mr, mrs->prob_avg);
945- eprob = MINSTREL_TRUNC(mrs->prob_avg * 1000);
946-
947- p += sprintf(p, "%u.%u,%u.%u,%u.%u,%u,%u,%u,"
948- "%llu,%llu,%d,%d\n",
949- tp_max / 10, tp_max % 10,
950- tp_avg / 10, tp_avg % 10,
951- eprob / 10, eprob % 10,
952- mrs->retry_count,
953- mrs->last_success,
954- mrs->last_attempts,
955- (unsigned long long)mrs->succ_hist,
956- (unsigned long long)mrs->att_hist,
957- mi->total_packets - mi->sample_packets,
958- mi->sample_packets);
959-
960- }
961- ms->len = p - ms->buf;
962-
963- WARN_ON(ms->len + sizeof(*ms) > 2048);
964-
965- return 0;
966-}
967--- a/net/mac80211/rc80211_minstrel_ht.c
968+++ b/net/mac80211/rc80211_minstrel_ht.c
969@@ -13,7 +13,6 @@
970 #include <net/mac80211.h>
971 #include "rate.h"
972 #include "sta_info.h"
973-#include "rc80211_minstrel.h"
974 #include "rc80211_minstrel_ht.h"
975
976 #define AVG_AMPDU_SIZE 16
977@@ -716,6 +715,83 @@ out:
978 mi->sample_mode = MINSTREL_SAMPLE_ACTIVE;
979 }
980
981+static inline int
982+minstrel_ewma(int old, int new, int weight)
983+{
984+ int diff, incr;
985+
986+ diff = new - old;
987+ incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
988+
989+ return old + incr;
990+}
991+
992+static inline int minstrel_filter_avg_add(u16 *prev_1, u16 *prev_2, s32 in)
993+{
994+ s32 out_1 = *prev_1;
995+ s32 out_2 = *prev_2;
996+ s32 val;
997+
998+ if (!in)
999+ in += 1;
1000+
1001+ if (!out_1) {
1002+ val = out_1 = in;
1003+ goto out;
1004+ }
1005+
1006+ val = MINSTREL_AVG_COEFF1 * in;
1007+ val += MINSTREL_AVG_COEFF2 * out_1;
1008+ val += MINSTREL_AVG_COEFF3 * out_2;
1009+ val >>= MINSTREL_SCALE;
1010+
1011+ if (val > 1 << MINSTREL_SCALE)
1012+ val = 1 << MINSTREL_SCALE;
1013+ if (val < 0)
1014+ val = 1;
1015+
1016+out:
1017+ *prev_2 = out_1;
1018+ *prev_1 = val;
1019+
1020+ return val;
1021+}
1022+
1023+/*
1024+* Recalculate statistics and counters of a given rate
1025+*/
1026+static void
1027+minstrel_ht_calc_rate_stats(struct minstrel_priv *mp,
1028+ struct minstrel_rate_stats *mrs)
1029+{
1030+ unsigned int cur_prob;
1031+
1032+ if (unlikely(mrs->attempts > 0)) {
1033+ mrs->sample_skipped = 0;
1034+ cur_prob = MINSTREL_FRAC(mrs->success, mrs->attempts);
1035+ if (mp->new_avg) {
1036+ minstrel_filter_avg_add(&mrs->prob_avg,
1037+ &mrs->prob_avg_1, cur_prob);
1038+ } else if (unlikely(!mrs->att_hist)) {
1039+ mrs->prob_avg = cur_prob;
1040+ } else {
1041+ /*update exponential weighted moving avarage */
1042+ mrs->prob_avg = minstrel_ewma(mrs->prob_avg,
1043+ cur_prob,
1044+ EWMA_LEVEL);
1045+ }
1046+ mrs->att_hist += mrs->attempts;
1047+ mrs->succ_hist += mrs->success;
1048+ } else {
1049+ mrs->sample_skipped++;
1050+ }
1051+
1052+ mrs->last_success = mrs->success;
1053+ mrs->last_attempts = mrs->attempts;
1054+ mrs->success = 0;
1055+ mrs->attempts = 0;
1056+}
1057+
1058 /*
1059 * Update rate statistics and select new primary rates
1060 *
1061@@ -808,7 +884,7 @@ minstrel_ht_update_stats(struct minstrel
1062
1063 mrs = &mg->rates[i];
1064 mrs->retry_updated = false;
1065- minstrel_calc_rate_stats(mp, mrs);
1066+ minstrel_ht_calc_rate_stats(mp, mrs);
1067 cur_prob = mrs->prob_avg;
1068
1069 if (minstrel_ht_get_tp_avg(mi, group, i, cur_prob) == 0)
1070@@ -960,8 +1036,7 @@ minstrel_ht_tx_status(void *priv, struct
1071 void *priv_sta, struct ieee80211_tx_status *st)
1072 {
1073 struct ieee80211_tx_info *info = st->info;
1074- struct minstrel_ht_sta_priv *msp = priv_sta;
1075- struct minstrel_ht_sta *mi = &msp->ht;
1076+ struct minstrel_ht_sta *mi = priv_sta;
1077 struct ieee80211_tx_rate *ar = info->status.rates;
1078 struct minstrel_rate_stats *rate, *rate2, *rate_sample = NULL;
1079 struct minstrel_priv *mp = priv;
1080@@ -1372,8 +1447,7 @@ minstrel_ht_get_rate(void *priv, struct
1081 const struct mcs_group *sample_group;
1082 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
1083 struct ieee80211_tx_rate *rate = &info->status.rates[0];
1084- struct minstrel_ht_sta_priv *msp = priv_sta;
1085- struct minstrel_ht_sta *mi = &msp->ht;
1086+ struct minstrel_ht_sta *mi = priv_sta;
1087 struct minstrel_priv *mp = priv;
1088 int sample_idx;
1089
1090@@ -1484,8 +1558,7 @@ minstrel_ht_update_caps(void *priv, stru
1091 struct ieee80211_sta *sta, void *priv_sta)
1092 {
1093 struct minstrel_priv *mp = priv;
1094- struct minstrel_ht_sta_priv *msp = priv_sta;
1095- struct minstrel_ht_sta *mi = &msp->ht;
1096+ struct minstrel_ht_sta *mi = priv_sta;
1097 struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs;
1098 u16 ht_cap = sta->ht_cap.cap;
1099 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1100@@ -1647,7 +1720,7 @@ static void *
1101 minstrel_ht_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
1102 {
1103 struct ieee80211_supported_band *sband;
1104- struct minstrel_ht_sta_priv *msp;
1105+ struct minstrel_ht_sta *mi;
1106 struct minstrel_priv *mp = priv;
1107 struct ieee80211_hw *hw = mp->hw;
1108 int max_rates = 0;
1109@@ -1659,35 +1732,13 @@ minstrel_ht_alloc_sta(void *priv, struct
1110 max_rates = sband->n_bitrates;
1111 }
1112
1113- msp = kzalloc(sizeof(*msp), gfp);
1114- if (!msp)
1115- return NULL;
1116-
1117- msp->ratelist = kcalloc(max_rates, sizeof(struct minstrel_rate), gfp);
1118- if (!msp->ratelist)
1119- goto error;
1120-
1121- msp->sample_table = kmalloc_array(max_rates, SAMPLE_COLUMNS, gfp);
1122- if (!msp->sample_table)
1123- goto error1;
1124-
1125- return msp;
1126-
1127-error1:
1128- kfree(msp->ratelist);
1129-error:
1130- kfree(msp);
1131- return NULL;
1132+ return kzalloc(sizeof(*mi), gfp);
1133 }
1134
1135 static void
1136 minstrel_ht_free_sta(void *priv, struct ieee80211_sta *sta, void *priv_sta)
1137 {
1138- struct minstrel_ht_sta_priv *msp = priv_sta;
1139-
1140- kfree(msp->sample_table);
1141- kfree(msp->ratelist);
1142- kfree(msp);
1143+ kfree(priv_sta);
1144 }
1145
1146 static void
1147@@ -1768,12 +1819,6 @@ minstrel_ht_alloc(struct ieee80211_hw *h
1148 mp->cw_min = 15;
1149 mp->cw_max = 1023;
1150
1151- /* number of packets (in %) to use for sampling other rates
1152- * sample less often for non-mrr packets, because the overhead
1153- * is much higher than with mrr */
1154- mp->lookaround_rate = 5;
1155- mp->lookaround_rate_mrr = 10;
1156-
1157 /* maximum time that the hw is allowed to stay in one MRR segment */
1158 mp->segment_size = 6000;
1159
1160@@ -1821,8 +1866,7 @@ minstrel_ht_free(void *priv)
1161
1162 static u32 minstrel_ht_get_expected_throughput(void *priv_sta)
1163 {
1164- struct minstrel_ht_sta_priv *msp = priv_sta;
1165- struct minstrel_ht_sta *mi = &msp->ht;
1166+ struct minstrel_ht_sta *mi = priv_sta;
1167 int i, j, prob, tp_avg;
1168
1169 i = mi->max_tp_rate[0] / MCS_GROUP_RATES;
1170--- a/net/mac80211/rc80211_minstrel_ht.h
1171+++ b/net/mac80211/rc80211_minstrel_ht.h
1172@@ -6,6 +6,33 @@
1173 #ifndef __RC_MINSTREL_HT_H
1174 #define __RC_MINSTREL_HT_H
1175
1176+/* number of highest throughput rates to consider*/
1177+#define MAX_THR_RATES 4
1178+#define SAMPLE_COLUMNS 10 /* number of columns in sample table */
1179+
1180+/* scaled fraction values */
1181+#define MINSTREL_SCALE 12
1182+#define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
1183+#define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
1184+
1185+#define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
1186+#define EWMA_DIV 128
1187+
1188+/*
1189+ * Coefficients for moving average with noise filter (period=16),
1190+ * scaled by 10 bits
1191+ *
1192+ * a1 = exp(-pi * sqrt(2) / period)
1193+ * coeff2 = 2 * a1 * cos(sqrt(2) * 2 * pi / period)
1194+ * coeff3 = -sqr(a1)
1195+ * coeff1 = 1 - coeff2 - coeff3
1196+ */
1197+#define MINSTREL_AVG_COEFF1 (MINSTREL_FRAC(1, 1) - \
1198+ MINSTREL_AVG_COEFF2 - \
1199+ MINSTREL_AVG_COEFF3)
1200+#define MINSTREL_AVG_COEFF2 0x00001499
1201+#define MINSTREL_AVG_COEFF3 -0x0000092e
1202+
1203 /*
1204 * The number of streams can be changed to 2 to reduce code
1205 * size and memory footprint.
1206@@ -30,6 +57,32 @@
1207
1208 #define MCS_GROUP_RATES 10
1209
1210+struct minstrel_priv {
1211+ struct ieee80211_hw *hw;
1212+ bool has_mrr;
1213+ bool new_avg;
1214+ u32 sample_switch;
1215+ unsigned int cw_min;
1216+ unsigned int cw_max;
1217+ unsigned int max_retry;
1218+ unsigned int segment_size;
1219+ unsigned int update_interval;
1220+
1221+ u8 cck_rates[4];
1222+ u8 ofdm_rates[NUM_NL80211_BANDS][8];
1223+
1224+#ifdef CPTCFG_MAC80211_DEBUGFS
1225+ /*
1226+ * enable fixed rate processing per RC
1227+ * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
1228+ * - write -1 to enable RC processing again
1229+ * - setting will be applied on next update
1230+ */
1231+ u32 fixed_rate_idx;
1232+#endif
1233+};
1234+
1235+
1236 struct mcs_group {
1237 u16 flags;
1238 u8 streams;
1239@@ -42,6 +95,26 @@ extern const s16 minstrel_cck_bitrates[4
1240 extern const s16 minstrel_ofdm_bitrates[8];
1241 extern const struct mcs_group minstrel_mcs_groups[];
1242
1243+struct minstrel_rate_stats {
1244+ /* current / last sampling period attempts/success counters */
1245+ u16 attempts, last_attempts;
1246+ u16 success, last_success;
1247+
1248+ /* total attempts/success counters */
1249+ u32 att_hist, succ_hist;
1250+
1251+ /* prob_avg - moving average of prob */
1252+ u16 prob_avg;
1253+ u16 prob_avg_1;
1254+
1255+ /* maximum retry counts */
1256+ u8 retry_count;
1257+ u8 retry_count_rtscts;
1258+
1259+ u8 sample_skipped;
1260+ bool retry_updated;
1261+};
1262+
1263 struct minstrel_mcs_group_data {
1264 u8 index;
1265 u8 column;
1266@@ -111,12 +184,6 @@ struct minstrel_ht_sta {
1267 struct minstrel_mcs_group_data groups[MINSTREL_GROUPS_NB];
1268 };
1269
1270-struct minstrel_ht_sta_priv {
1271- struct minstrel_ht_sta ht;
1272- void *ratelist;
1273- void *sample_table;
1274-};
1275-
1276 void minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
1277 int minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate,
1278 int prob_avg);
1279--- a/net/mac80211/rc80211_minstrel_ht_debugfs.c
1280+++ b/net/mac80211/rc80211_minstrel_ht_debugfs.c
1281@@ -9,9 +9,13 @@
1282 #include <linux/ieee80211.h>
1283 #include <linux/export.h>
1284 #include <net/mac80211.h>
1285-#include "rc80211_minstrel.h"
1286 #include "rc80211_minstrel_ht.h"
1287
1288+struct minstrel_debugfs_info {
1289+ size_t len;
1290+ char buf[];
1291+};
1292+
1293 static ssize_t
1294 minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
1295 {
1296@@ -127,8 +131,7 @@ minstrel_ht_stats_dump(struct minstrel_h
1297 static int
1298 minstrel_ht_stats_open(struct inode *inode, struct file *file)
1299 {
1300- struct minstrel_ht_sta_priv *msp = inode->i_private;
1301- struct minstrel_ht_sta *mi = &msp->ht;
1302+ struct minstrel_ht_sta *mi = inode->i_private;
1303 struct minstrel_debugfs_info *ms;
1304 unsigned int i;
1305 char *p;
1306@@ -276,8 +279,7 @@ minstrel_ht_stats_csv_dump(struct minstr
1307 static int
1308 minstrel_ht_stats_csv_open(struct inode *inode, struct file *file)
1309 {
1310- struct minstrel_ht_sta_priv *msp = inode->i_private;
1311- struct minstrel_ht_sta *mi = &msp->ht;
1312+ struct minstrel_ht_sta *mi = inode->i_private;
1313 struct minstrel_debugfs_info *ms;
1314 unsigned int i;
1315 char *p;
1316@@ -313,10 +315,8 @@ static const struct file_operations mins
1317 void
1318 minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
1319 {
1320- struct minstrel_ht_sta_priv *msp = priv_sta;
1321-
1322- debugfs_create_file("rc_stats", 0444, dir, msp,
1323+ debugfs_create_file("rc_stats", 0444, dir, priv_sta,
1324 &minstrel_ht_stat_fops);
1325- debugfs_create_file("rc_stats_csv", 0444, dir, msp,
1326+ debugfs_create_file("rc_stats_csv", 0444, dir, priv_sta,
1327 &minstrel_ht_stat_csv_fops);
1328 }