rc80211_minstrel_ht.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2010 Felix Fietkau <[email protected]>
  4. */
  5. #ifndef __RC_MINSTREL_HT_H
  6. #define __RC_MINSTREL_HT_H
  7. #include <linux/bitfield.h>
  8. /* number of highest throughput rates to consider*/
  9. #define MAX_THR_RATES 4
  10. #define SAMPLE_COLUMNS 10 /* number of columns in sample table */
  11. /* scaled fraction values */
  12. #define MINSTREL_SCALE 12
  13. #define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div)
  14. #define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE)
  15. #define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
  16. #define EWMA_DIV 128
  17. /*
  18. * Coefficients for moving average with noise filter (period=16),
  19. * scaled by 10 bits
  20. *
  21. * a1 = exp(-pi * sqrt(2) / period)
  22. * coeff2 = 2 * a1 * cos(sqrt(2) * 2 * pi / period)
  23. * coeff3 = -sqr(a1)
  24. * coeff1 = 1 - coeff2 - coeff3
  25. */
  26. #define MINSTREL_AVG_COEFF1 (MINSTREL_FRAC(1, 1) - \
  27. MINSTREL_AVG_COEFF2 - \
  28. MINSTREL_AVG_COEFF3)
  29. #define MINSTREL_AVG_COEFF2 0x00001499
  30. #define MINSTREL_AVG_COEFF3 -0x0000092e
  31. /*
  32. * The number of streams can be changed to 2 to reduce code
  33. * size and memory footprint.
  34. */
  35. #define MINSTREL_MAX_STREAMS 4
  36. #define MINSTREL_HT_STREAM_GROUPS 4 /* BW(=2) * SGI(=2) */
  37. #define MINSTREL_VHT_STREAM_GROUPS 6 /* BW(=3) * SGI(=2) */
  38. #define MINSTREL_HT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
  39. MINSTREL_HT_STREAM_GROUPS)
  40. #define MINSTREL_VHT_GROUPS_NB (MINSTREL_MAX_STREAMS * \
  41. MINSTREL_VHT_STREAM_GROUPS)
  42. #define MINSTREL_LEGACY_GROUPS_NB 2
  43. #define MINSTREL_GROUPS_NB (MINSTREL_HT_GROUPS_NB + \
  44. MINSTREL_VHT_GROUPS_NB + \
  45. MINSTREL_LEGACY_GROUPS_NB)
  46. #define MINSTREL_HT_GROUP_0 0
  47. #define MINSTREL_CCK_GROUP (MINSTREL_HT_GROUP_0 + MINSTREL_HT_GROUPS_NB)
  48. #define MINSTREL_OFDM_GROUP (MINSTREL_CCK_GROUP + 1)
  49. #define MINSTREL_VHT_GROUP_0 (MINSTREL_OFDM_GROUP + 1)
  50. #define MCS_GROUP_RATES 10
  51. #define MI_RATE_IDX_MASK GENMASK(3, 0)
  52. #define MI_RATE_GROUP_MASK GENMASK(15, 4)
  53. #define MI_RATE(_group, _idx) \
  54. (FIELD_PREP(MI_RATE_GROUP_MASK, _group) | \
  55. FIELD_PREP(MI_RATE_IDX_MASK, _idx))
  56. #define MI_RATE_IDX(_rate) FIELD_GET(MI_RATE_IDX_MASK, _rate)
  57. #define MI_RATE_GROUP(_rate) FIELD_GET(MI_RATE_GROUP_MASK, _rate)
  58. #define MINSTREL_SAMPLE_RATES 5 /* rates per sample type */
  59. #define MINSTREL_SAMPLE_INTERVAL (HZ / 50)
  60. struct minstrel_priv {
  61. struct ieee80211_hw *hw;
  62. bool has_mrr;
  63. unsigned int cw_min;
  64. unsigned int cw_max;
  65. unsigned int max_retry;
  66. unsigned int segment_size;
  67. unsigned int update_interval;
  68. u8 cck_rates[4];
  69. u8 ofdm_rates[NUM_NL80211_BANDS][8];
  70. #ifdef CONFIG_MAC80211_DEBUGFS
  71. /*
  72. * enable fixed rate processing per RC
  73. * - write static index to debugfs:ieee80211/phyX/rc/fixed_rate_idx
  74. * - write -1 to enable RC processing again
  75. * - setting will be applied on next update
  76. */
  77. u32 fixed_rate_idx;
  78. #endif
  79. };
  80. struct mcs_group {
  81. u16 flags;
  82. u8 streams;
  83. u8 shift;
  84. u8 bw;
  85. u16 duration[MCS_GROUP_RATES];
  86. };
  87. extern const s16 minstrel_cck_bitrates[4];
  88. extern const s16 minstrel_ofdm_bitrates[8];
  89. extern const struct mcs_group minstrel_mcs_groups[];
  90. struct minstrel_rate_stats {
  91. /* current / last sampling period attempts/success counters */
  92. u16 attempts, last_attempts;
  93. u16 success, last_success;
  94. /* total attempts/success counters */
  95. u32 att_hist, succ_hist;
  96. /* prob_avg - moving average of prob */
  97. u16 prob_avg;
  98. u16 prob_avg_1;
  99. /* maximum retry counts */
  100. u8 retry_count;
  101. u8 retry_count_rtscts;
  102. bool retry_updated;
  103. };
  104. enum minstrel_sample_type {
  105. MINSTREL_SAMPLE_TYPE_INC,
  106. MINSTREL_SAMPLE_TYPE_JUMP,
  107. MINSTREL_SAMPLE_TYPE_SLOW,
  108. __MINSTREL_SAMPLE_TYPE_MAX
  109. };
  110. struct minstrel_mcs_group_data {
  111. u8 index;
  112. u8 column;
  113. /* sorted rate set within a MCS group*/
  114. u16 max_group_tp_rate[MAX_THR_RATES];
  115. u16 max_group_prob_rate;
  116. /* MCS rate statistics */
  117. struct minstrel_rate_stats rates[MCS_GROUP_RATES];
  118. };
  119. struct minstrel_sample_category {
  120. u8 sample_group;
  121. u16 sample_rates[MINSTREL_SAMPLE_RATES];
  122. u16 cur_sample_rates[MINSTREL_SAMPLE_RATES];
  123. };
  124. struct minstrel_ht_sta {
  125. struct ieee80211_sta *sta;
  126. /* ampdu length (average, per sampling interval) */
  127. unsigned int ampdu_len;
  128. unsigned int ampdu_packets;
  129. /* ampdu length (EWMA) */
  130. unsigned int avg_ampdu_len;
  131. /* overall sorted rate set */
  132. u16 max_tp_rate[MAX_THR_RATES];
  133. u16 max_prob_rate;
  134. /* time of last status update */
  135. unsigned long last_stats_update;
  136. /* overhead time in usec for each frame */
  137. unsigned int overhead;
  138. unsigned int overhead_rtscts;
  139. unsigned int overhead_legacy;
  140. unsigned int overhead_legacy_rtscts;
  141. unsigned int total_packets;
  142. unsigned int sample_packets;
  143. /* tx flags to add for frames for this sta */
  144. u32 tx_flags;
  145. bool use_short_preamble;
  146. u8 band;
  147. u8 sample_seq;
  148. u16 sample_rate;
  149. unsigned long sample_time;
  150. struct minstrel_sample_category sample[__MINSTREL_SAMPLE_TYPE_MAX];
  151. /* Bitfield of supported MCS rates of all groups */
  152. u16 supported[MINSTREL_GROUPS_NB];
  153. /* MCS rate group info and statistics */
  154. struct minstrel_mcs_group_data groups[MINSTREL_GROUPS_NB];
  155. };
  156. void minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir);
  157. int minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate,
  158. int prob_avg);
  159. #endif