rc.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 MAX_TX_RATE_PHY 48
  25. #define RC_INVALID 0x0000
  26. #define RC_LEGACY 0x0001
  27. #define RC_SS 0x0002
  28. #define RC_DS 0x0004
  29. #define RC_TS 0x0008
  30. #define RC_HT_20 0x0010
  31. #define RC_HT_40 0x0020
  32. #define RC_STREAM_MASK 0xe
  33. #define RC_DS_OR_LATER(f) ((((f) & RC_STREAM_MASK) == RC_DS) || \
  34. (((f) & RC_STREAM_MASK) == (RC_DS | RC_TS)))
  35. #define RC_TS_ONLY(f) (((f) & RC_STREAM_MASK) == RC_TS)
  36. #define RC_SS_OR_LEGACY(f) ((f) & (RC_SS | RC_LEGACY))
  37. #define RC_HT_2040 (RC_HT_20 | RC_HT_40)
  38. #define RC_ALL_STREAM (RC_SS | RC_DS | RC_TS)
  39. #define RC_L_SD (RC_LEGACY | RC_SS | RC_DS)
  40. #define RC_L_SDT (RC_LEGACY | RC_SS | RC_DS | RC_TS)
  41. #define RC_HT_S_20 (RC_HT_20 | RC_SS)
  42. #define RC_HT_D_20 (RC_HT_20 | RC_DS)
  43. #define RC_HT_T_20 (RC_HT_20 | RC_TS)
  44. #define RC_HT_S_40 (RC_HT_40 | RC_SS)
  45. #define RC_HT_D_40 (RC_HT_40 | RC_DS)
  46. #define RC_HT_T_40 (RC_HT_40 | RC_TS)
  47. #define RC_HT_SD_20 (RC_HT_20 | RC_SS | RC_DS)
  48. #define RC_HT_DT_20 (RC_HT_20 | RC_DS | RC_TS)
  49. #define RC_HT_SD_40 (RC_HT_40 | RC_SS | RC_DS)
  50. #define RC_HT_DT_40 (RC_HT_40 | RC_DS | RC_TS)
  51. #define RC_HT_SD_2040 (RC_HT_2040 | RC_SS | RC_DS)
  52. #define RC_HT_SDT_2040 (RC_HT_2040 | RC_SS | RC_DS | RC_TS)
  53. #define RC_HT_SDT_20 (RC_HT_20 | RC_SS | RC_DS | RC_TS)
  54. #define RC_HT_SDT_40 (RC_HT_40 | RC_SS | RC_DS | RC_TS)
  55. #define RC_ALL (RC_LEGACY | RC_HT_2040 | RC_ALL_STREAM)
  56. enum {
  57. WLAN_RC_PHY_OFDM,
  58. WLAN_RC_PHY_CCK,
  59. WLAN_RC_PHY_HT_20_SS,
  60. WLAN_RC_PHY_HT_20_DS,
  61. WLAN_RC_PHY_HT_20_TS,
  62. WLAN_RC_PHY_HT_40_SS,
  63. WLAN_RC_PHY_HT_40_DS,
  64. WLAN_RC_PHY_HT_40_TS,
  65. WLAN_RC_PHY_HT_20_SS_HGI,
  66. WLAN_RC_PHY_HT_20_DS_HGI,
  67. WLAN_RC_PHY_HT_20_TS_HGI,
  68. WLAN_RC_PHY_HT_40_SS_HGI,
  69. WLAN_RC_PHY_HT_40_DS_HGI,
  70. WLAN_RC_PHY_HT_40_TS_HGI,
  71. WLAN_RC_PHY_MAX
  72. };
  73. #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
  74. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  75. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  76. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  77. #define WLAN_RC_PHY_TS(_phy) ((_phy == WLAN_RC_PHY_HT_20_TS) \
  78. || (_phy == WLAN_RC_PHY_HT_40_TS) \
  79. || (_phy == WLAN_RC_PHY_HT_20_TS_HGI) \
  80. || (_phy == WLAN_RC_PHY_HT_40_TS_HGI))
  81. #define WLAN_RC_PHY_20(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS) \
  82. || (_phy == WLAN_RC_PHY_HT_20_DS) \
  83. || (_phy == WLAN_RC_PHY_HT_20_TS) \
  84. || (_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
  85. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  86. || (_phy == WLAN_RC_PHY_HT_20_TS_HGI))
  87. #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
  88. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  89. || (_phy == WLAN_RC_PHY_HT_40_TS) \
  90. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  91. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI) \
  92. || (_phy == WLAN_RC_PHY_HT_40_TS_HGI))
  93. #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
  94. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  95. || (_phy == WLAN_RC_PHY_HT_20_TS_HGI) \
  96. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  97. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI) \
  98. || (_phy == WLAN_RC_PHY_HT_40_TS_HGI))
  99. #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
  100. #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
  101. ((capflag & WLAN_RC_40_FLAG) ? RC_HT_40 : RC_HT_20) : RC_LEGACY))
  102. #define WLAN_RC_CAP_STREAM(capflag) (((capflag & WLAN_RC_TS_FLAG) ? \
  103. (RC_TS) : ((capflag & WLAN_RC_DS_FLAG) ? RC_DS : RC_SS)))
  104. /* Return TRUE if flag supports HT20 && client supports HT20 or
  105. * return TRUE if flag supports HT40 && client supports HT40.
  106. * This is used becos some rates overlap between HT20/HT40.
  107. */
  108. #define WLAN_RC_PHY_HT_VALID(flag, capflag) \
  109. (((flag & RC_HT_20) && !(capflag & WLAN_RC_40_FLAG)) || \
  110. ((flag & RC_HT_40) && (capflag & WLAN_RC_40_FLAG)))
  111. #define WLAN_RC_DS_FLAG (0x01)
  112. #define WLAN_RC_TS_FLAG (0x02)
  113. #define WLAN_RC_40_FLAG (0x04)
  114. #define WLAN_RC_SGI_FLAG (0x08)
  115. #define WLAN_RC_HT_FLAG (0x10)
  116. /**
  117. * struct ath_rate_table - Rate Control table
  118. * @rate_cnt: total number of rates for the given wireless mode
  119. * @mcs_start: MCS rate index offset
  120. * @rate_flags: Rate Control flags
  121. * @phy: CCK/OFDM/HT20/HT40
  122. * @ratekbps: rate in Kbits per second
  123. * @user_ratekbps: user rate in Kbits per second
  124. * @ratecode: rate that goes into HW descriptors
  125. * @dot11rate: value that goes into supported
  126. * rates info element of MLME
  127. * @ctrl_rate: Index of next lower basic rate, used for duration computation
  128. * @cw40index: Index of rates having 40MHz channel width
  129. * @sgi_index: Index of rates having Short Guard Interval
  130. * @ht_index: high throughput rates having 40MHz channel width and
  131. * Short Guard Interval
  132. * @probe_interval: interval for rate control to probe for other rates
  133. * @initial_ratemax: initial ratemax value
  134. */
  135. struct ath_rate_table {
  136. int rate_cnt;
  137. int mcs_start;
  138. struct {
  139. u16 rate_flags;
  140. u8 phy;
  141. u32 ratekbps;
  142. u32 user_ratekbps;
  143. u8 ratecode;
  144. u8 dot11rate;
  145. u8 ctrl_rate;
  146. u8 cw40index;
  147. u8 sgi_index;
  148. u8 ht_index;
  149. } info[RATE_TABLE_SIZE];
  150. u32 probe_interval;
  151. u8 initial_ratemax;
  152. };
  153. struct ath_rateset {
  154. u8 rs_nrates;
  155. u8 rs_rates[ATH_RATE_MAX];
  156. };
  157. struct ath_rc_stats {
  158. u32 success;
  159. u32 retries;
  160. u32 xretries;
  161. u8 per;
  162. };
  163. /**
  164. * struct ath_rate_priv - Rate Control priv data
  165. * @state: RC state
  166. * @probe_rate: rate we are probing at
  167. * @probe_time: msec timestamp for last probe
  168. * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
  169. * @max_valid_rate: maximum number of valid rate
  170. * @per_down_time: msec timestamp for last PER down step
  171. * @valid_phy_ratecnt: valid rate count
  172. * @rate_max_phy: phy index for the max rate
  173. * @per: PER for every valid rate in %
  174. * @probe_interval: interval for ratectrl to probe for other rates
  175. * @ht_cap: HT capabilities
  176. * @neg_rates: Negotatied rates
  177. * @neg_ht_rates: Negotiated HT rates
  178. */
  179. struct ath_rate_priv {
  180. u8 rate_table_size;
  181. u8 probe_rate;
  182. u8 hw_maxretry_pktcnt;
  183. u8 max_valid_rate;
  184. u8 valid_rate_index[RATE_TABLE_SIZE];
  185. u8 ht_cap;
  186. u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
  187. u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
  188. u8 rate_max_phy;
  189. u8 per[RATE_TABLE_SIZE];
  190. u32 probe_time;
  191. u32 per_down_time;
  192. u32 probe_interval;
  193. struct ath_rateset neg_rates;
  194. struct ath_rateset neg_ht_rates;
  195. const struct ath_rate_table *rate_table;
  196. struct dentry *debugfs_rcstats;
  197. struct ath_rc_stats rcstats[RATE_TABLE_SIZE];
  198. };
  199. enum ath9k_internal_frame_type {
  200. ATH9K_IFT_NOT_INTERNAL,
  201. ATH9K_IFT_PAUSE,
  202. ATH9K_IFT_UNPAUSE
  203. };
  204. #ifdef CONFIG_ATH9K_RATE_CONTROL
  205. int ath_rate_control_register(void);
  206. void ath_rate_control_unregister(void);
  207. #else
  208. static inline int ath_rate_control_register(void)
  209. {
  210. return 0;
  211. }
  212. static inline void ath_rate_control_unregister(void)
  213. {
  214. }
  215. #endif
  216. #endif /* RC_H */