rc80211_minstrel.h 2.9 KB

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