Blame view

net/mac80211/rc80211_minstrel.h 4.11 KB
cccf129f8   Felix Fietkau   mac80211: add the...
1
2
3
4
5
6
7
8
9
10
  /*
   * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
  
  #ifndef __RC_MINSTREL_H
  #define __RC_MINSTREL_H
eea85999e   Karl Beldan   mac80211: optimiz...
11
12
  #define EWMA_LEVEL	96	/* ewma weighting factor [/EWMA_DIV] */
  #define EWMA_DIV	128
f744bf81f   Thomas Huehn   mac80211: add low...
13
  #define SAMPLE_COLUMNS	10	/* number of columns in sample table */
c8ca8c2f9   Thomas Huehn   mac80211: merge v...
14
  /* scaled fraction values */
0217eefa6   Felix Fietkau   mac80211: minstre...
15
  #define MINSTREL_SCALE  12
c8ca8c2f9   Thomas Huehn   mac80211: merge v...
16
17
  #define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
  #define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
2ff2b690c   Thomas Huehn   mac80211: improve...
18
19
  /* number of highest throughput rates to consider*/
  #define MAX_THR_RATES 4
a512d4b54   Thomas Huehn   mac80211: merge E...
20
21
  /*
   * Perform EWMA (Exponentially Weighted Moving Average) calculation
6d4885177   Thomas Huehn   mac80211: add new...
22
   */
a512d4b54   Thomas Huehn   mac80211: merge E...
23
24
25
  static inline int
  minstrel_ewma(int old, int new, int weight)
  {
ade6d4a2e   Thomas Huehn   mac80211: reduce ...
26
27
28
29
30
31
  	int diff, incr;
  
  	diff = new - old;
  	incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
  
  	return old + incr;
a512d4b54   Thomas Huehn   mac80211: merge E...
32
  }
5f919abc7   Thomas Huehn   mac80211: add sta...
33
  /*
4f0bc9c61   Felix Fietkau   mac80211: minstre...
34
   * Perform EWMV (Exponentially Weighted Moving Variance) calculation
5f919abc7   Thomas Huehn   mac80211: add sta...
35
36
   */
  static inline int
4f0bc9c61   Felix Fietkau   mac80211: minstre...
37
  minstrel_ewmv(int old_ewmv, int cur_prob, int prob_ewma, int weight)
5f919abc7   Thomas Huehn   mac80211: add sta...
38
  {
4f0bc9c61   Felix Fietkau   mac80211: minstre...
39
  	int diff, incr;
5f919abc7   Thomas Huehn   mac80211: add sta...
40

4f0bc9c61   Felix Fietkau   mac80211: minstre...
41
  	diff = cur_prob - prob_ewma;
5f919abc7   Thomas Huehn   mac80211: add sta...
42
  	incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
4f0bc9c61   Felix Fietkau   mac80211: minstre...
43
  	return weight * (old_ewmv + MINSTREL_TRUNC(diff * incr)) / EWMA_DIV;
5f919abc7   Thomas Huehn   mac80211: add sta...
44
  }
ca12c0c83   Thomas Huehn   mac80211: Unify r...
45
46
  struct minstrel_rate_stats {
  	/* current / last sampling period attempts/success counters */
8d819a92c   Felix Fietkau   mac80211: minstre...
47
48
  	u16 attempts, last_attempts;
  	u16 success, last_success;
ca12c0c83   Thomas Huehn   mac80211: Unify r...
49
50
  
  	/* total attempts/success counters */
70550df2d   Felix Fietkau   mac80211: minstre...
51
  	u32 att_hist, succ_hist;
ca12c0c83   Thomas Huehn   mac80211: Unify r...
52

9134073bc   Thomas Huehn   mac80211: improve...
53
  	/* statistis of packet delivery probability
5f919abc7   Thomas Huehn   mac80211: add sta...
54
55
  	 *  prob_ewma - exponential weighted moving average of prob
  	 *  prob_ewmsd - exp. weighted moving standard deviation of prob */
4cae4cd10   Felix Fietkau   mac80211: minstre...
56
  	u16 prob_ewma;
4f0bc9c61   Felix Fietkau   mac80211: minstre...
57
  	u16 prob_ewmv;
ca12c0c83   Thomas Huehn   mac80211: Unify r...
58
59
  
  	/* maximum retry counts */
8d819a92c   Felix Fietkau   mac80211: minstre...
60
61
  	u8 retry_count;
  	u8 retry_count_rtscts;
ca12c0c83   Thomas Huehn   mac80211: Unify r...
62
63
64
65
  
  	u8 sample_skipped;
  	bool retry_updated;
  };
a512d4b54   Thomas Huehn   mac80211: merge E...
66

cccf129f8   Felix Fietkau   mac80211: add the...
67
68
  struct minstrel_rate {
  	int bitrate;
8d819a92c   Felix Fietkau   mac80211: minstre...
69
70
71
72
  
  	s8 rix;
  	u8 retry_count_cts;
  	u8 adjusted_retry_count;
cccf129f8   Felix Fietkau   mac80211: add the...
73
74
75
  
  	unsigned int perfect_tx_time;
  	unsigned int ack_time;
f4a8cd94f   Felix Fietkau   minstrel: improve...
76
  	int sample_limit;
cccf129f8   Felix Fietkau   mac80211: add the...
77

ca12c0c83   Thomas Huehn   mac80211: Unify r...
78
  	struct minstrel_rate_stats stats;
cccf129f8   Felix Fietkau   mac80211: add the...
79
80
81
  };
  
  struct minstrel_sta_info {
06d961a8e   Felix Fietkau   mac80211/minstrel...
82
  	struct ieee80211_sta *sta;
9134073bc   Thomas Huehn   mac80211: improve...
83
  	unsigned long last_stats_update;
cccf129f8   Felix Fietkau   mac80211: add the...
84
85
86
87
  	unsigned int sp_ack_dur;
  	unsigned int rate_avg;
  
  	unsigned int lowest_rix;
2ff2b690c   Thomas Huehn   mac80211: improve...
88
89
  	u8 max_tp_rate[MAX_THR_RATES];
  	u8 max_prob_rate;
ca12c0c83   Thomas Huehn   mac80211: Unify r...
90
91
  	unsigned int total_packets;
  	unsigned int sample_packets;
cccf129f8   Felix Fietkau   mac80211: add the...
92
  	int sample_deferred;
8f1576119   Thomas Huehn   mac80211: add doc...
93
  	unsigned int sample_row;
cccf129f8   Felix Fietkau   mac80211: add the...
94
95
96
97
  	unsigned int sample_column;
  
  	int n_rates;
  	struct minstrel_rate *r;
f4a8cd94f   Felix Fietkau   minstrel: improve...
98
  	bool prev_sample;
cccf129f8   Felix Fietkau   mac80211: add the...
99
100
101
102
103
104
  
  	/* sampling table */
  	u8 *sample_table;
  
  #ifdef CONFIG_MAC80211_DEBUGFS
  	struct dentry *dbg_stats;
6d4885177   Thomas Huehn   mac80211: add new...
105
  	struct dentry *dbg_stats_csv;
cccf129f8   Felix Fietkau   mac80211: add the...
106
107
108
109
110
111
112
113
114
  #endif
  };
  
  struct minstrel_priv {
  	struct ieee80211_hw *hw;
  	bool has_mrr;
  	unsigned int cw_min;
  	unsigned int cw_max;
  	unsigned int max_retry;
cccf129f8   Felix Fietkau   mac80211: add the...
115
116
117
118
  	unsigned int segment_size;
  	unsigned int update_interval;
  	unsigned int lookaround_rate;
  	unsigned int lookaround_rate_mrr;
24f7580e8   Zefir Kurtisi   minstrel_ht: fixe...
119

a0497f9f5   Felix Fietkau   mac80211/minstrel...
120
  	u8 cck_rates[4];
24f7580e8   Zefir Kurtisi   minstrel_ht: fixe...
121
122
123
124
125
126
127
128
129
130
  #ifdef CONFIG_MAC80211_DEBUGFS
  	/*
  	 * enable fixed rate processing per RC
  	 *   - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
  	 *   - write -1 to enable RC processing again
  	 *   - setting will be applied on next update
  	 */
  	u32 fixed_rate_idx;
  	struct dentry *dbg_fixed_rate;
  #endif
cccf129f8   Felix Fietkau   mac80211: add the...
131
  };
44ac91ea8   Felix Fietkau   minstrel: simplif...
132
133
134
135
  struct minstrel_debugfs_info {
  	size_t len;
  	char buf[];
  };
4f0bc9c61   Felix Fietkau   mac80211: minstre...
136
137
138
139
140
141
142
  /* Get EWMSD (Exponentially Weighted Moving Standard Deviation) * 10 */
  static inline int
  minstrel_get_ewmsd10(struct minstrel_rate_stats *mrs)
  {
  	unsigned int ewmv = mrs->prob_ewmv;
  	return int_sqrt(MINSTREL_TRUNC(ewmv * 1000 * 1000));
  }
631ad703b   Johannes Berg   mac80211: make ra...
143
  extern const struct rate_control_ops mac80211_minstrel;
cccf129f8   Felix Fietkau   mac80211: add the...
144
145
  void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
  void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
f62838bcc   Thomas Huehn   mac80211: unify M...
146
  /* Recalculate success probabilities and counters for a given rate using EWMA */
9134073bc   Thomas Huehn   mac80211: improve...
147
  void minstrel_calc_rate_stats(struct minstrel_rate_stats *mrs);
50e55a8ea   Thomas Huehn   mac80211: add max...
148
  int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_ewma);
f62838bcc   Thomas Huehn   mac80211: unify M...
149

eae44756d   Felix Fietkau   minstrel: make th...
150
151
  /* debugfs */
  int minstrel_stats_open(struct inode *inode, struct file *file);
6d4885177   Thomas Huehn   mac80211: add new...
152
  int minstrel_stats_csv_open(struct inode *inode, struct file *file);
eae44756d   Felix Fietkau   minstrel: make th...
153
154
  ssize_t minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos);
  int minstrel_stats_release(struct inode *inode, struct file *file);
cccf129f8   Felix Fietkau   mac80211: add the...
155
  #endif