Merge tag 'iommu-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux/fpc-iii.git] / net / mac80211 / rc80211_minstrel.h
blob86cd80b3ffdef8423ea39069c1e8ac0e6f5bd560
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
4 */
6 #ifndef __RC_MINSTREL_H
7 #define __RC_MINSTREL_H
9 #define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
10 #define EWMA_DIV 128
11 #define SAMPLE_COLUMNS 10 /* number of columns in sample table */
13 /* scaled fraction values */
14 #define MINSTREL_SCALE 12
15 #define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
16 #define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
18 /* number of highest throughput rates to consider*/
19 #define MAX_THR_RATES 4
22 * Coefficients for moving average with noise filter (period=16),
23 * scaled by 10 bits
25 * a1 = exp(-pi * sqrt(2) / period)
26 * coeff2 = 2 * a1 * cos(sqrt(2) * 2 * pi / period)
27 * coeff3 = -sqr(a1)
28 * coeff1 = 1 - coeff2 - coeff3
30 #define MINSTREL_AVG_COEFF1 (MINSTREL_FRAC(1, 1) - \
31 MINSTREL_AVG_COEFF2 - \
32 MINSTREL_AVG_COEFF3)
33 #define MINSTREL_AVG_COEFF2 0x00001499
34 #define MINSTREL_AVG_COEFF3 -0x0000092e
37 * Perform EWMA (Exponentially Weighted Moving Average) calculation
39 static inline int
40 minstrel_ewma(int old, int new, int weight)
42 int diff, incr;
44 diff = new - old;
45 incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
47 return old + incr;
50 static inline int minstrel_filter_avg_add(u16 *prev_1, u16 *prev_2, s32 in)
52 s32 out_1 = *prev_1;
53 s32 out_2 = *prev_2;
54 s32 val;
56 if (!in)
57 in += 1;
59 if (!out_1) {
60 val = out_1 = in;
61 goto out;
64 val = MINSTREL_AVG_COEFF1 * in;
65 val += MINSTREL_AVG_COEFF2 * out_1;
66 val += MINSTREL_AVG_COEFF3 * out_2;
67 val >>= MINSTREL_SCALE;
69 if (val > 1 << MINSTREL_SCALE)
70 val = 1 << MINSTREL_SCALE;
71 if (val < 0)
72 val = 1;
74 out:
75 *prev_2 = out_1;
76 *prev_1 = val;
78 return val;
81 struct minstrel_rate_stats {
82 /* current / last sampling period attempts/success counters */
83 u16 attempts, last_attempts;
84 u16 success, last_success;
86 /* total attempts/success counters */
87 u32 att_hist, succ_hist;
89 /* prob_avg - moving average of prob */
90 u16 prob_avg;
91 u16 prob_avg_1;
93 /* maximum retry counts */
94 u8 retry_count;
95 u8 retry_count_rtscts;
97 u8 sample_skipped;
98 bool retry_updated;
101 struct minstrel_rate {
102 int bitrate;
104 s8 rix;
105 u8 retry_count_cts;
106 u8 adjusted_retry_count;
108 unsigned int perfect_tx_time;
109 unsigned int ack_time;
111 int sample_limit;
113 struct minstrel_rate_stats stats;
116 struct minstrel_sta_info {
117 struct ieee80211_sta *sta;
119 unsigned long last_stats_update;
120 unsigned int sp_ack_dur;
121 unsigned int rate_avg;
123 unsigned int lowest_rix;
125 u8 max_tp_rate[MAX_THR_RATES];
126 u8 max_prob_rate;
127 unsigned int total_packets;
128 unsigned int sample_packets;
130 unsigned int sample_row;
131 unsigned int sample_column;
133 int n_rates;
134 struct minstrel_rate *r;
135 bool prev_sample;
137 /* sampling table */
138 u8 *sample_table;
141 struct minstrel_priv {
142 struct ieee80211_hw *hw;
143 bool has_mrr;
144 bool new_avg;
145 u32 sample_switch;
146 unsigned int cw_min;
147 unsigned int cw_max;
148 unsigned int max_retry;
149 unsigned int segment_size;
150 unsigned int update_interval;
151 unsigned int lookaround_rate;
152 unsigned int lookaround_rate_mrr;
154 u8 cck_rates[4];
156 #ifdef CONFIG_MAC80211_DEBUGFS
158 * enable fixed rate processing per RC
159 * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
160 * - write -1 to enable RC processing again
161 * - setting will be applied on next update
163 u32 fixed_rate_idx;
164 #endif
167 struct minstrel_debugfs_info {
168 size_t len;
169 char buf[];
172 extern const struct rate_control_ops mac80211_minstrel;
173 void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
175 /* Recalculate success probabilities and counters for a given rate using EWMA */
176 void minstrel_calc_rate_stats(struct minstrel_priv *mp,
177 struct minstrel_rate_stats *mrs);
178 int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_avg);
180 /* debugfs */
181 int minstrel_stats_open(struct inode *inode, struct file *file);
182 int minstrel_stats_csv_open(struct inode *inode, struct file *file);
184 #endif