rc.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright (c) 2004 Sam Leffler, Errno Consulting
  3. * Copyright (c) 2004 Video54 Technologies, Inc.
  4. * Copyright (c) 2008 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 "ath9k.h"
  21. /*
  22. * Interface definitions for transmit rate control modules for the
  23. * Atheros driver.
  24. *
  25. * A rate control module is responsible for choosing the transmit rate
  26. * for each data frame. Management+control frames are always sent at
  27. * a fixed rate.
  28. *
  29. * Only one module may be present at a time; the driver references
  30. * rate control interfaces by symbol name. If multiple modules are
  31. * to be supported we'll need to switch to a registration-based scheme
  32. * as is currently done, for example, for authentication modules.
  33. *
  34. * An instance of the rate control module is attached to each device
  35. * at attach time and detached when the device is destroyed. The module
  36. * may associate data with each device and each node (station). Both
  37. * sets of storage are opaque except for the size of the per-node storage
  38. * which must be provided when the module is attached.
  39. *
  40. * The rate control module is notified for each state transition and
  41. * station association/reassociation. Otherwise it is queried for a
  42. * rate for each outgoing frame and provided status from each transmitted
  43. * frame. Any ancillary processing is the responsibility of the module
  44. * (e.g. if periodic processing is required then the module should setup
  45. * it's own timer).
  46. *
  47. * In addition to the transmit rate for each frame the module must also
  48. * indicate the number of attempts to make at the specified rate. If this
  49. * number is != ATH_TXMAXTRY then an additional callback is made to setup
  50. * additional transmit state. The rate control code is assumed to write
  51. * this additional data directly to the transmit descriptor.
  52. */
  53. struct ath_softc;
  54. #define TRUE 1
  55. #define FALSE 0
  56. #define ATH_RATE_MAX 30
  57. #define WLAN_PHY_HT_20_SS WLAN_RC_PHY_HT_20_SS
  58. #define WLAN_PHY_HT_20_DS WLAN_RC_PHY_HT_20_DS
  59. #define WLAN_PHY_HT_20_DS_HGI WLAN_RC_PHY_HT_20_DS_HGI
  60. #define WLAN_PHY_HT_40_SS WLAN_RC_PHY_HT_40_SS
  61. #define WLAN_PHY_HT_40_SS_HGI WLAN_RC_PHY_HT_40_SS_HGI
  62. #define WLAN_PHY_HT_40_DS WLAN_RC_PHY_HT_40_DS
  63. #define WLAN_PHY_HT_40_DS_HGI WLAN_RC_PHY_HT_40_DS_HGI
  64. #define WLAN_PHY_OFDM PHY_OFDM
  65. #define WLAN_PHY_CCK PHY_CCK
  66. #define TRUE_20 0x2
  67. #define TRUE_40 0x4
  68. #define TRUE_2040 (TRUE_20|TRUE_40)
  69. #define TRUE_ALL (TRUE_2040|TRUE)
  70. enum {
  71. WLAN_RC_PHY_HT_20_SS = 4,
  72. WLAN_RC_PHY_HT_20_DS,
  73. WLAN_RC_PHY_HT_40_SS,
  74. WLAN_RC_PHY_HT_40_DS,
  75. WLAN_RC_PHY_HT_20_SS_HGI,
  76. WLAN_RC_PHY_HT_20_DS_HGI,
  77. WLAN_RC_PHY_HT_40_SS_HGI,
  78. WLAN_RC_PHY_HT_40_DS_HGI,
  79. WLAN_RC_PHY_MAX
  80. };
  81. #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
  82. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  83. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  84. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  85. #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
  86. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  87. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  88. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  89. #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
  90. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  91. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  92. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  93. #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
  94. /* Returns the capflag mode */
  95. #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
  96. (capflag & WLAN_RC_40_FLAG) ? TRUE_40 : TRUE_20 : TRUE))
  97. /* Return TRUE if flag supports HT20 && client supports HT20 or
  98. * return TRUE if flag supports HT40 && client supports HT40.
  99. * This is used becos some rates overlap between HT20/HT40.
  100. */
  101. #define WLAN_RC_PHY_HT_VALID(flag, capflag) (((flag & TRUE_20) && !(capflag \
  102. & WLAN_RC_40_FLAG)) || ((flag & TRUE_40) && \
  103. (capflag & WLAN_RC_40_FLAG)))
  104. #define WLAN_RC_DS_FLAG (0x01)
  105. #define WLAN_RC_40_FLAG (0x02)
  106. #define WLAN_RC_SGI_FLAG (0x04)
  107. #define WLAN_RC_HT_FLAG (0x08)
  108. #define RATE_TABLE_SIZE 64
  109. /**
  110. * struct ath_rate_table - Rate Control table
  111. * @valid: valid for use in rate control
  112. * @valid_single_stream: valid for use in rate control for
  113. * single stream operation
  114. * @phy: CCK/OFDM
  115. * @ratekbps: rate in Kbits per second
  116. * @user_ratekbps: user rate in Kbits per second
  117. * @ratecode: rate that goes into HW descriptors
  118. * @short_preamble: Mask for enabling short preamble in ratecode for CCK
  119. * @dot11rate: value that goes into supported
  120. * rates info element of MLME
  121. * @ctrl_rate: Index of next lower basic rate, used for duration computation
  122. * @max_4ms_framelen: maximum frame length(bytes) for tx duration
  123. * @probe_interval: interval for rate control to probe for other rates
  124. * @rssi_reduce_interval: interval for rate control to reduce rssi
  125. * @initial_ratemax: initial ratemax value used in ath_rc_sib_update()
  126. */
  127. struct ath_rate_table {
  128. int rate_cnt;
  129. struct {
  130. int valid;
  131. int valid_single_stream;
  132. u8 phy;
  133. u32 ratekbps;
  134. u32 user_ratekbps;
  135. u8 ratecode;
  136. u8 short_preamble;
  137. u8 dot11rate;
  138. u8 ctrl_rate;
  139. int8_t rssi_ack_validmin;
  140. int8_t rssi_ack_deltamin;
  141. u8 base_index;
  142. u8 cw40index;
  143. u8 sgi_index;
  144. u8 ht_index;
  145. u32 max_4ms_framelen;
  146. } info[RATE_TABLE_SIZE];
  147. u32 probe_interval;
  148. u32 rssi_reduce_interval;
  149. u8 initial_ratemax;
  150. };
  151. #define ATH_RC_PROBE_ALLOWED 0x00000001
  152. #define ATH_RC_MINRATE_LASTRATE 0x00000002
  153. /*
  154. * State structures for new rate adaptation code
  155. */
  156. #define MAX_TX_RATE_TBL 64
  157. #define MAX_TX_RATE_PHY 48
  158. struct ath_tx_ratectrl_state {
  159. int8_t rssi_thres; /* required rssi for this rate (dB) */
  160. u8 per; /* recent estimate of packet error rate (%) */
  161. };
  162. struct ath_rateset {
  163. u8 rs_nrates;
  164. u8 rs_rates[ATH_RATE_MAX];
  165. };
  166. /**
  167. * struct ath_rate_node - Rate Control priv data
  168. * @state: RC state
  169. * @rssi_last: last ACK rssi
  170. * @rssi_last_lookup: last ACK rssi used for lookup
  171. * @rssi_last_prev: previous last ACK rssi
  172. * @rssi_last_prev2: 2nd previous last ACK rssi
  173. * @rssi_sum_cnt: count of rssi_sum for averaging
  174. * @rssi_sum_rate: rate that we are averaging
  175. * @rssi_sum: running sum of rssi for averaging
  176. * @probe_rate: rate we are probing at
  177. * @rssi_time: msec timestamp for last ack rssi
  178. * @rssi_down_time: msec timestamp for last down step
  179. * @probe_time: msec timestamp for last probe
  180. * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
  181. * @max_valid_rate: maximum number of valid rate
  182. * @per_down_time: msec timestamp for last PER down step
  183. * @valid_phy_ratecnt: valid rate count
  184. * @rate_max_phy: phy index for the max rate
  185. * @probe_interval: interval for ratectrl to probe for other rates
  186. * @prev_data_rix: rate idx of last data frame
  187. * @ht_cap: HT capabilities
  188. * @single_stream: When TRUE, only single TX stream possible
  189. * @neg_rates: Negotatied rates
  190. * @neg_ht_rates: Negotiated HT rates
  191. */
  192. /* per-node state */
  193. struct ath_rate_node {
  194. int8_t rssi_last;
  195. int8_t rssi_last_lookup;
  196. int8_t rssi_last_prev;
  197. int8_t rssi_last_prev2;
  198. int32_t rssi_sum_cnt;
  199. int32_t rssi_sum_rate;
  200. int32_t rssi_sum;
  201. u8 rate_table_size;
  202. u8 probe_rate;
  203. u8 hw_maxretry_pktcnt;
  204. u8 max_valid_rate;
  205. u8 valid_rate_index[MAX_TX_RATE_TBL];
  206. u8 ht_cap;
  207. u8 single_stream;
  208. u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
  209. u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][MAX_TX_RATE_TBL];
  210. u8 rc_phy_mode;
  211. u8 rate_max_phy;
  212. u32 rssi_time;
  213. u32 rssi_down_time;
  214. u32 probe_time;
  215. u32 per_down_time;
  216. u32 probe_interval;
  217. u32 prev_data_rix;
  218. u32 tx_triglevel_max;
  219. struct ath_tx_ratectrl_state state[MAX_TX_RATE_TBL];
  220. struct ath_rateset neg_rates;
  221. struct ath_rateset neg_ht_rates;
  222. struct ath_rate_softc *asc;
  223. };
  224. struct ath_tx_info_priv {
  225. struct ath_tx_status tx;
  226. int n_frames;
  227. int n_bad_frames;
  228. };
  229. void ath_rate_attach(struct ath_softc *sc);
  230. u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
  231. int ath_rate_control_register(void);
  232. void ath_rate_control_unregister(void);
  233. #endif /* RC_H */