David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __RC_MINSTREL_H |
| 7 | #define __RC_MINSTREL_H |
| 8 | |
| 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 */ |
| 12 | |
| 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) |
| 17 | |
| 18 | /* number of highest throughput rates to consider*/ |
| 19 | #define MAX_THR_RATES 4 |
| 20 | |
| 21 | /* |
| 22 | * Perform EWMA (Exponentially Weighted Moving Average) calculation |
| 23 | */ |
| 24 | static inline int |
| 25 | minstrel_ewma(int old, int new, int weight) |
| 26 | { |
| 27 | int diff, incr; |
| 28 | |
| 29 | diff = new - old; |
| 30 | incr = (EWMA_DIV - weight) * diff / EWMA_DIV; |
| 31 | |
| 32 | return old + incr; |
| 33 | } |
| 34 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 35 | struct minstrel_rate_stats { |
| 36 | /* current / last sampling period attempts/success counters */ |
| 37 | u16 attempts, last_attempts; |
| 38 | u16 success, last_success; |
| 39 | |
| 40 | /* total attempts/success counters */ |
| 41 | u32 att_hist, succ_hist; |
| 42 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 43 | /* prob_ewma - exponential weighted moving average of prob */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 44 | u16 prob_ewma; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 45 | |
| 46 | /* maximum retry counts */ |
| 47 | u8 retry_count; |
| 48 | u8 retry_count_rtscts; |
| 49 | |
| 50 | u8 sample_skipped; |
| 51 | bool retry_updated; |
| 52 | }; |
| 53 | |
| 54 | struct minstrel_rate { |
| 55 | int bitrate; |
| 56 | |
| 57 | s8 rix; |
| 58 | u8 retry_count_cts; |
| 59 | u8 adjusted_retry_count; |
| 60 | |
| 61 | unsigned int perfect_tx_time; |
| 62 | unsigned int ack_time; |
| 63 | |
| 64 | int sample_limit; |
| 65 | |
| 66 | struct minstrel_rate_stats stats; |
| 67 | }; |
| 68 | |
| 69 | struct minstrel_sta_info { |
| 70 | struct ieee80211_sta *sta; |
| 71 | |
| 72 | unsigned long last_stats_update; |
| 73 | unsigned int sp_ack_dur; |
| 74 | unsigned int rate_avg; |
| 75 | |
| 76 | unsigned int lowest_rix; |
| 77 | |
| 78 | u8 max_tp_rate[MAX_THR_RATES]; |
| 79 | u8 max_prob_rate; |
| 80 | unsigned int total_packets; |
| 81 | unsigned int sample_packets; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 82 | |
| 83 | unsigned int sample_row; |
| 84 | unsigned int sample_column; |
| 85 | |
| 86 | int n_rates; |
| 87 | struct minstrel_rate *r; |
| 88 | bool prev_sample; |
| 89 | |
| 90 | /* sampling table */ |
| 91 | u8 *sample_table; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct minstrel_priv { |
| 95 | struct ieee80211_hw *hw; |
| 96 | bool has_mrr; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 97 | u32 sample_switch; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 98 | unsigned int cw_min; |
| 99 | unsigned int cw_max; |
| 100 | unsigned int max_retry; |
| 101 | unsigned int segment_size; |
| 102 | unsigned int update_interval; |
| 103 | unsigned int lookaround_rate; |
| 104 | unsigned int lookaround_rate_mrr; |
| 105 | |
| 106 | u8 cck_rates[4]; |
| 107 | |
| 108 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 109 | /* |
| 110 | * enable fixed rate processing per RC |
| 111 | * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx |
| 112 | * - write -1 to enable RC processing again |
| 113 | * - setting will be applied on next update |
| 114 | */ |
| 115 | u32 fixed_rate_idx; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 116 | #endif |
| 117 | }; |
| 118 | |
| 119 | struct minstrel_debugfs_info { |
| 120 | size_t len; |
| 121 | char buf[]; |
| 122 | }; |
| 123 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 124 | extern const struct rate_control_ops mac80211_minstrel; |
| 125 | void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 126 | |
| 127 | /* Recalculate success probabilities and counters for a given rate using EWMA */ |
| 128 | void minstrel_calc_rate_stats(struct minstrel_rate_stats *mrs); |
| 129 | int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_ewma); |
| 130 | |
| 131 | /* debugfs */ |
| 132 | int minstrel_stats_open(struct inode *inode, struct file *file); |
| 133 | int minstrel_stats_csv_open(struct inode *inode, struct file *file); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 134 | |
| 135 | #endif |