rc80211_minstrel.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __RC_MINSTREL_H
  9. #define __RC_MINSTREL_H
  10. #define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
  11. #define EWMA_DIV 128
  12. #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)
  17. /* number of highest throughput rates to consider*/
  18. #define MAX_THR_RATES 4
  19. /*
  20. * Perform EWMA (Exponentially Weighted Moving Average) calculation
  21. */
  22. static inline int
  23. minstrel_ewma(int old, int new, int weight)
  24. {
  25. int diff, incr;
  26. diff = new - old;
  27. incr = (EWMA_DIV - weight) * diff / EWMA_DIV;
  28. return old + incr;
  29. }
  30. struct minstrel_rate_stats {
  31. /* current / last sampling period attempts/success counters */
  32. u16 attempts, last_attempts;
  33. u16 success, last_success;
  34. /* total attempts/success counters */
  35. u32 att_hist, succ_hist;
  36. /* prob_ewma - exponential weighted moving average of prob */
  37. u16 prob_ewma;
  38. /* maximum retry counts */
  39. u8 retry_count;
  40. u8 retry_count_rtscts;
  41. u8 sample_skipped;
  42. bool retry_updated;
  43. };
  44. struct minstrel_rate {
  45. int bitrate;
  46. s8 rix;
  47. u8 retry_count_cts;
  48. u8 adjusted_retry_count;
  49. unsigned int perfect_tx_time;
  50. unsigned int ack_time;
  51. int sample_limit;
  52. struct minstrel_rate_stats stats;
  53. };
  54. struct minstrel_sta_info {
  55. struct ieee80211_sta *sta;
  56. unsigned long last_stats_update;
  57. unsigned int sp_ack_dur;
  58. unsigned int rate_avg;
  59. unsigned int lowest_rix;
  60. u8 max_tp_rate[MAX_THR_RATES];
  61. u8 max_prob_rate;
  62. unsigned int total_packets;
  63. unsigned int sample_packets;
  64. int sample_deferred;
  65. unsigned int sample_row;
  66. unsigned int sample_column;
  67. int n_rates;
  68. struct minstrel_rate *r;
  69. bool prev_sample;
  70. /* sampling table */
  71. u8 *sample_table;
  72. };
  73. struct minstrel_priv {
  74. struct ieee80211_hw *hw;
  75. bool has_mrr;
  76. unsigned int cw_min;
  77. unsigned int cw_max;
  78. unsigned int max_retry;
  79. unsigned int segment_size;
  80. unsigned int update_interval;
  81. unsigned int lookaround_rate;
  82. unsigned int lookaround_rate_mrr;
  83. u8 cck_rates[4];
  84. #ifdef CONFIG_MAC80211_DEBUGFS
  85. /*
  86. * enable fixed rate processing per RC
  87. * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
  88. * - write -1 to enable RC processing again
  89. * - setting will be applied on next update
  90. */
  91. u32 fixed_rate_idx;
  92. #endif
  93. };
  94. struct minstrel_debugfs_info {
  95. size_t len;
  96. char buf[];
  97. };
  98. extern const struct rate_control_ops mac80211_minstrel;
  99. void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
  100. /* Recalculate success probabilities and counters for a given rate using EWMA */
  101. void minstrel_calc_rate_stats(struct minstrel_rate_stats *mrs);
  102. int minstrel_get_tp_avg(struct minstrel_rate *mr, int prob_ewma);
  103. /* debugfs */
  104. int minstrel_stats_open(struct inode *inode, struct file *file);
  105. int minstrel_stats_csv_open(struct inode *inode, struct file *file);
  106. #endif