rc80211_minstrel.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 16
  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. return (new * (EWMA_DIV - weight) + old * weight) / EWMA_DIV;
  26. }
  27. struct minstrel_rate_stats {
  28. /* current / last sampling period attempts/success counters */
  29. unsigned int attempts, last_attempts;
  30. unsigned int success, last_success;
  31. /* total attempts/success counters */
  32. u64 att_hist, succ_hist;
  33. /* current throughput */
  34. unsigned int cur_tp;
  35. /* packet delivery probabilities */
  36. unsigned int cur_prob, probability;
  37. /* maximum retry counts */
  38. unsigned int retry_count;
  39. unsigned int retry_count_rtscts;
  40. u8 sample_skipped;
  41. bool retry_updated;
  42. };
  43. struct minstrel_rate {
  44. int bitrate;
  45. int rix;
  46. unsigned int perfect_tx_time;
  47. unsigned int ack_time;
  48. int sample_limit;
  49. unsigned int retry_count_cts;
  50. unsigned int adjusted_retry_count;
  51. struct minstrel_rate_stats stats;
  52. };
  53. struct minstrel_sta_info {
  54. struct ieee80211_sta *sta;
  55. unsigned long stats_update;
  56. unsigned int sp_ack_dur;
  57. unsigned int rate_avg;
  58. unsigned int lowest_rix;
  59. u8 max_tp_rate[MAX_THR_RATES];
  60. u8 max_prob_rate;
  61. unsigned int total_packets;
  62. unsigned int sample_packets;
  63. int sample_deferred;
  64. unsigned int sample_row;
  65. unsigned int sample_column;
  66. int n_rates;
  67. struct minstrel_rate *r;
  68. bool prev_sample;
  69. /* sampling table */
  70. u8 *sample_table;
  71. #ifdef CONFIG_MAC80211_DEBUGFS
  72. struct dentry *dbg_stats;
  73. #endif
  74. };
  75. struct minstrel_priv {
  76. struct ieee80211_hw *hw;
  77. bool has_mrr;
  78. unsigned int cw_min;
  79. unsigned int cw_max;
  80. unsigned int max_retry;
  81. unsigned int segment_size;
  82. unsigned int update_interval;
  83. unsigned int lookaround_rate;
  84. unsigned int lookaround_rate_mrr;
  85. u8 cck_rates[4];
  86. #ifdef CONFIG_MAC80211_DEBUGFS
  87. /*
  88. * enable fixed rate processing per RC
  89. * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
  90. * - write -1 to enable RC processing again
  91. * - setting will be applied on next update
  92. */
  93. u32 fixed_rate_idx;
  94. struct dentry *dbg_fixed_rate;
  95. #endif
  96. };
  97. struct minstrel_debugfs_info {
  98. size_t len;
  99. char buf[];
  100. };
  101. extern const struct rate_control_ops mac80211_minstrel;
  102. void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
  103. void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
  104. /* debugfs */
  105. int minstrel_stats_open(struct inode *inode, struct file *file);
  106. ssize_t minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos);
  107. int minstrel_stats_release(struct inode *inode, struct file *file);
  108. #endif