rc.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (c) 2004 Sam Leffler, Errno Consulting
  3. * Copyright (c) 2004 Video54 Technologies, Inc.
  4. * Copyright (c) 2008-2011 Atheros Communications Inc.
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef RC_H
  19. #define RC_H
  20. #include "hw.h"
  21. struct ath_softc;
  22. #define ATH_RATE_MAX 30
  23. #define RATE_TABLE_SIZE 72
  24. #define RC_INVALID 0x0000
  25. #define RC_LEGACY 0x0001
  26. #define RC_SS 0x0002
  27. #define RC_DS 0x0004
  28. #define RC_TS 0x0008
  29. #define RC_HT_20 0x0010
  30. #define RC_HT_40 0x0020
  31. #define RC_STREAM_MASK 0xe
  32. #define RC_DS_OR_LATER(f) ((((f) & RC_STREAM_MASK) == RC_DS) || \
  33. (((f) & RC_STREAM_MASK) == (RC_DS | RC_TS)))
  34. #define RC_TS_ONLY(f) (((f) & RC_STREAM_MASK) == RC_TS)
  35. #define RC_SS_OR_LEGACY(f) ((f) & (RC_SS | RC_LEGACY))
  36. #define RC_HT_2040 (RC_HT_20 | RC_HT_40)
  37. #define RC_ALL_STREAM (RC_SS | RC_DS | RC_TS)
  38. #define RC_L_SD (RC_LEGACY | RC_SS | RC_DS)
  39. #define RC_L_SDT (RC_LEGACY | RC_SS | RC_DS | RC_TS)
  40. #define RC_HT_S_20 (RC_HT_20 | RC_SS)
  41. #define RC_HT_D_20 (RC_HT_20 | RC_DS)
  42. #define RC_HT_T_20 (RC_HT_20 | RC_TS)
  43. #define RC_HT_S_40 (RC_HT_40 | RC_SS)
  44. #define RC_HT_D_40 (RC_HT_40 | RC_DS)
  45. #define RC_HT_T_40 (RC_HT_40 | RC_TS)
  46. #define RC_HT_SD_20 (RC_HT_20 | RC_SS | RC_DS)
  47. #define RC_HT_DT_20 (RC_HT_20 | RC_DS | RC_TS)
  48. #define RC_HT_SD_40 (RC_HT_40 | RC_SS | RC_DS)
  49. #define RC_HT_DT_40 (RC_HT_40 | RC_DS | RC_TS)
  50. #define RC_HT_SD_2040 (RC_HT_2040 | RC_SS | RC_DS)
  51. #define RC_HT_SDT_2040 (RC_HT_2040 | RC_SS | RC_DS | RC_TS)
  52. #define RC_HT_SDT_20 (RC_HT_20 | RC_SS | RC_DS | RC_TS)
  53. #define RC_HT_SDT_40 (RC_HT_40 | RC_SS | RC_DS | RC_TS)
  54. #define RC_ALL (RC_LEGACY | RC_HT_2040 | RC_ALL_STREAM)
  55. enum {
  56. WLAN_RC_PHY_OFDM,
  57. WLAN_RC_PHY_CCK,
  58. WLAN_RC_PHY_HT_20_SS,
  59. WLAN_RC_PHY_HT_20_DS,
  60. WLAN_RC_PHY_HT_20_TS,
  61. WLAN_RC_PHY_HT_40_SS,
  62. WLAN_RC_PHY_HT_40_DS,
  63. WLAN_RC_PHY_HT_40_TS,
  64. WLAN_RC_PHY_HT_20_SS_HGI,
  65. WLAN_RC_PHY_HT_20_DS_HGI,
  66. WLAN_RC_PHY_HT_20_TS_HGI,
  67. WLAN_RC_PHY_HT_40_SS_HGI,
  68. WLAN_RC_PHY_HT_40_DS_HGI,
  69. WLAN_RC_PHY_HT_40_TS_HGI,
  70. WLAN_RC_PHY_MAX
  71. };
  72. #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
  73. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  74. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  75. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  76. #define WLAN_RC_PHY_TS(_phy) ((_phy == WLAN_RC_PHY_HT_20_TS) \
  77. || (_phy == WLAN_RC_PHY_HT_40_TS) \
  78. || (_phy == WLAN_RC_PHY_HT_20_TS_HGI) \
  79. || (_phy == WLAN_RC_PHY_HT_40_TS_HGI))
  80. #define WLAN_RC_PHY_20(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS) \
  81. || (_phy == WLAN_RC_PHY_HT_20_DS) \
  82. || (_phy == WLAN_RC_PHY_HT_20_TS) \
  83. || (_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
  84. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  85. || (_phy == WLAN_RC_PHY_HT_20_TS_HGI))
  86. #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
  87. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  88. || (_phy == WLAN_RC_PHY_HT_40_TS) \
  89. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  90. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI) \
  91. || (_phy == WLAN_RC_PHY_HT_40_TS_HGI))
  92. #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
  93. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  94. || (_phy == WLAN_RC_PHY_HT_20_TS_HGI) \
  95. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  96. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI) \
  97. || (_phy == WLAN_RC_PHY_HT_40_TS_HGI))
  98. #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
  99. #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
  100. ((capflag & WLAN_RC_40_FLAG) ? RC_HT_40 : RC_HT_20) : RC_LEGACY))
  101. #define WLAN_RC_CAP_STREAM(capflag) (((capflag & WLAN_RC_TS_FLAG) ? \
  102. (RC_TS) : ((capflag & WLAN_RC_DS_FLAG) ? RC_DS : RC_SS)))
  103. /* Return TRUE if flag supports HT20 && client supports HT20 or
  104. * return TRUE if flag supports HT40 && client supports HT40.
  105. * This is used becos some rates overlap between HT20/HT40.
  106. */
  107. #define WLAN_RC_PHY_HT_VALID(flag, capflag) \
  108. (((flag & RC_HT_20) && !(capflag & WLAN_RC_40_FLAG)) || \
  109. ((flag & RC_HT_40) && (capflag & WLAN_RC_40_FLAG)))
  110. #define WLAN_RC_DS_FLAG (0x01)
  111. #define WLAN_RC_TS_FLAG (0x02)
  112. #define WLAN_RC_40_FLAG (0x04)
  113. #define WLAN_RC_SGI_FLAG (0x08)
  114. #define WLAN_RC_HT_FLAG (0x10)
  115. /**
  116. * struct ath_rate_table - Rate Control table
  117. * @rate_cnt: total number of rates for the given wireless mode
  118. * @mcs_start: MCS rate index offset
  119. * @rate_flags: Rate Control flags
  120. * @phy: CCK/OFDM/HT20/HT40
  121. * @ratekbps: rate in Kbits per second
  122. * @user_ratekbps: user rate in Kbits per second
  123. * @ratecode: rate that goes into HW descriptors
  124. * @dot11rate: value that goes into supported
  125. * rates info element of MLME
  126. * @ctrl_rate: Index of next lower basic rate, used for duration computation
  127. * @cw40index: Index of rates having 40MHz channel width
  128. * @sgi_index: Index of rates having Short Guard Interval
  129. * @ht_index: high throughput rates having 40MHz channel width and
  130. * Short Guard Interval
  131. * @probe_interval: interval for rate control to probe for other rates
  132. * @initial_ratemax: initial ratemax value
  133. */
  134. struct ath_rate_table {
  135. int rate_cnt;
  136. int mcs_start;
  137. struct {
  138. u16 rate_flags;
  139. u8 phy;
  140. u32 ratekbps;
  141. u32 user_ratekbps;
  142. u8 ratecode;
  143. u8 dot11rate;
  144. u8 ctrl_rate;
  145. u8 cw40index;
  146. u8 sgi_index;
  147. u8 ht_index;
  148. } info[RATE_TABLE_SIZE];
  149. u32 probe_interval;
  150. u8 initial_ratemax;
  151. };
  152. struct ath_rateset {
  153. u8 rs_nrates;
  154. u8 rs_rates[ATH_RATE_MAX];
  155. };
  156. struct ath_rc_stats {
  157. u32 success;
  158. u32 retries;
  159. u32 xretries;
  160. u8 per;
  161. };
  162. /**
  163. * struct ath_rate_priv - Rate Control priv data
  164. * @state: RC state
  165. * @probe_rate: rate we are probing at
  166. * @probe_time: msec timestamp for last probe
  167. * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
  168. * @max_valid_rate: maximum number of valid rate
  169. * @per_down_time: msec timestamp for last PER down step
  170. * @valid_phy_ratecnt: valid rate count
  171. * @rate_max_phy: phy index for the max rate
  172. * @per: PER for every valid rate in %
  173. * @probe_interval: interval for ratectrl to probe for other rates
  174. * @ht_cap: HT capabilities
  175. * @neg_rates: Negotatied rates
  176. * @neg_ht_rates: Negotiated HT rates
  177. */
  178. struct ath_rate_priv {
  179. u8 rate_table_size;
  180. u8 probe_rate;
  181. u8 hw_maxretry_pktcnt;
  182. u8 max_valid_rate;
  183. u8 valid_rate_index[RATE_TABLE_SIZE];
  184. u8 ht_cap;
  185. u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
  186. u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
  187. u8 rate_max_phy;
  188. u8 per[RATE_TABLE_SIZE];
  189. u32 probe_time;
  190. u32 per_down_time;
  191. u32 probe_interval;
  192. struct ath_rateset neg_rates;
  193. struct ath_rateset neg_ht_rates;
  194. const struct ath_rate_table *rate_table;
  195. struct dentry *debugfs_rcstats;
  196. struct ath_rc_stats rcstats[RATE_TABLE_SIZE];
  197. };
  198. #ifdef CONFIG_ATH9K_RATE_CONTROL
  199. int ath_rate_control_register(void);
  200. void ath_rate_control_unregister(void);
  201. #else
  202. static inline int ath_rate_control_register(void)
  203. {
  204. return 0;
  205. }
  206. static inline void ath_rate_control_unregister(void)
  207. {
  208. }
  209. #endif
  210. #endif /* RC_H */