rc80211_minstrel.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 75 /* ewma weighting factor [%] */
  11. #define SAMPLE_COLUMNS 10 /* number of columns in sample table */
  12. /* scaled fraction values */
  13. #define MINSTREL_SCALE 16
  14. #define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
  15. #define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
  16. /* number of highest throughput rates to consider*/
  17. #define MAX_THR_RATES 4
  18. /*
  19. * Perform EWMA (Exponentially Weighted Moving Average) calculation
  20. */
  21. static inline int
  22. minstrel_ewma(int old, int new, int weight)
  23. {
  24. return (new * (100 - weight) + old * weight) / 100;
  25. }
  26. struct minstrel_rate {
  27. int bitrate;
  28. int rix;
  29. unsigned int perfect_tx_time;
  30. unsigned int ack_time;
  31. int sample_limit;
  32. unsigned int retry_count;
  33. unsigned int retry_count_cts;
  34. unsigned int retry_count_rtscts;
  35. unsigned int adjusted_retry_count;
  36. u32 success;
  37. u32 attempts;
  38. u32 last_attempts;
  39. u32 last_success;
  40. u8 sample_skipped;
  41. /* parts per thousand */
  42. u32 cur_prob;
  43. u32 probability;
  44. /* per-rate throughput */
  45. u32 cur_tp;
  46. u64 succ_hist;
  47. u64 att_hist;
  48. };
  49. struct minstrel_sta_info {
  50. unsigned long stats_update;
  51. unsigned int sp_ack_dur;
  52. unsigned int rate_avg;
  53. unsigned int lowest_rix;
  54. u8 max_tp_rate[MAX_THR_RATES];
  55. u8 max_prob_rate;
  56. unsigned int packet_count;
  57. unsigned int sample_count;
  58. int sample_deferred;
  59. unsigned int sample_row;
  60. unsigned int sample_column;
  61. int n_rates;
  62. struct minstrel_rate *r;
  63. bool prev_sample;
  64. /* sampling table */
  65. u8 *sample_table;
  66. #ifdef CONFIG_MAC80211_DEBUGFS
  67. struct dentry *dbg_stats;
  68. #endif
  69. };
  70. struct minstrel_priv {
  71. struct ieee80211_hw *hw;
  72. bool has_mrr;
  73. unsigned int cw_min;
  74. unsigned int cw_max;
  75. unsigned int max_retry;
  76. unsigned int segment_size;
  77. unsigned int update_interval;
  78. unsigned int lookaround_rate;
  79. unsigned int lookaround_rate_mrr;
  80. u8 cck_rates[4];
  81. #ifdef CONFIG_MAC80211_DEBUGFS
  82. /*
  83. * enable fixed rate processing per RC
  84. * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
  85. * - write -1 to enable RC processing again
  86. * - setting will be applied on next update
  87. */
  88. u32 fixed_rate_idx;
  89. struct dentry *dbg_fixed_rate;
  90. #endif
  91. };
  92. struct minstrel_debugfs_info {
  93. size_t len;
  94. char buf[];
  95. };
  96. extern struct rate_control_ops mac80211_minstrel;
  97. void minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
  98. void minstrel_remove_sta_debugfs(void *priv, void *priv_sta);
  99. /* debugfs */
  100. int minstrel_stats_open(struct inode *inode, struct file *file);
  101. ssize_t minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos);
  102. int minstrel_stats_release(struct inode *inode, struct file *file);
  103. #endif