rc.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. struct ath_softc;
  22. #define ATH_RATE_MAX 30
  23. #define RATE_TABLE_SIZE 64
  24. #define MAX_TX_RATE_PHY 48
  25. /* VALID_ALL - valid for 20/40/Legacy,
  26. * VALID - Legacy only,
  27. * VALID_20 - HT 20 only,
  28. * VALID_40 - HT 40 only */
  29. #define INVALID 0x0
  30. #define VALID 0x1
  31. #define VALID_20 0x2
  32. #define VALID_40 0x4
  33. #define VALID_2040 (VALID_20|VALID_40)
  34. #define VALID_ALL (VALID_2040|VALID)
  35. #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
  36. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  37. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  38. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  39. #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
  40. || (_phy == WLAN_RC_PHY_HT_40_DS) \
  41. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  42. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  43. #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
  44. || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
  45. || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
  46. || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
  47. #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
  48. #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
  49. (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID))
  50. /* Return TRUE if flag supports HT20 && client supports HT20 or
  51. * return TRUE if flag supports HT40 && client supports HT40.
  52. * This is used becos some rates overlap between HT20/HT40.
  53. */
  54. #define WLAN_RC_PHY_HT_VALID(flag, capflag) \
  55. (((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \
  56. ((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG)))
  57. #define WLAN_RC_DS_FLAG (0x01)
  58. #define WLAN_RC_40_FLAG (0x02)
  59. #define WLAN_RC_SGI_FLAG (0x04)
  60. #define WLAN_RC_HT_FLAG (0x08)
  61. /**
  62. * struct ath_rate_table - Rate Control table
  63. * @valid: valid for use in rate control
  64. * @valid_single_stream: valid for use in rate control for
  65. * single stream operation
  66. * @phy: CCK/OFDM
  67. * @ratekbps: rate in Kbits per second
  68. * @user_ratekbps: user rate in Kbits per second
  69. * @ratecode: rate that goes into HW descriptors
  70. * @short_preamble: Mask for enabling short preamble in ratecode for CCK
  71. * @dot11rate: value that goes into supported
  72. * rates info element of MLME
  73. * @ctrl_rate: Index of next lower basic rate, used for duration computation
  74. * @max_4ms_framelen: maximum frame length(bytes) for tx duration
  75. * @probe_interval: interval for rate control to probe for other rates
  76. * @rssi_reduce_interval: interval for rate control to reduce rssi
  77. * @initial_ratemax: initial ratemax value
  78. */
  79. struct ath_rate_table {
  80. int rate_cnt;
  81. u8 rateCodeToIndex[256];
  82. struct {
  83. int valid;
  84. int valid_single_stream;
  85. u8 phy;
  86. u32 ratekbps;
  87. u32 user_ratekbps;
  88. u8 ratecode;
  89. u8 short_preamble;
  90. u8 dot11rate;
  91. u8 ctrl_rate;
  92. int8_t rssi_ack_validmin;
  93. int8_t rssi_ack_deltamin;
  94. u8 base_index;
  95. u8 cw40index;
  96. u8 sgi_index;
  97. u8 ht_index;
  98. u32 max_4ms_framelen;
  99. u16 lpAckDuration;
  100. u16 spAckDuration;
  101. } info[RATE_TABLE_SIZE];
  102. u32 probe_interval;
  103. u32 rssi_reduce_interval;
  104. u8 initial_ratemax;
  105. };
  106. struct ath_tx_ratectrl_state {
  107. int8_t rssi_thres; /* required rssi for this rate (dB) */
  108. u8 per; /* recent estimate of packet error rate (%) */
  109. };
  110. struct ath_rateset {
  111. u8 rs_nrates;
  112. u8 rs_rates[ATH_RATE_MAX];
  113. };
  114. /**
  115. * struct ath_rate_priv - Rate Control priv data
  116. * @state: RC state
  117. * @rssi_last: last ACK rssi
  118. * @rssi_last_lookup: last ACK rssi used for lookup
  119. * @rssi_last_prev: previous last ACK rssi
  120. * @rssi_last_prev2: 2nd previous last ACK rssi
  121. * @rssi_sum_cnt: count of rssi_sum for averaging
  122. * @rssi_sum_rate: rate that we are averaging
  123. * @rssi_sum: running sum of rssi for averaging
  124. * @probe_rate: rate we are probing at
  125. * @rssi_time: msec timestamp for last ack rssi
  126. * @rssi_down_time: msec timestamp for last down step
  127. * @probe_time: msec timestamp for last probe
  128. * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
  129. * @max_valid_rate: maximum number of valid rate
  130. * @per_down_time: msec timestamp for last PER down step
  131. * @valid_phy_ratecnt: valid rate count
  132. * @rate_max_phy: phy index for the max rate
  133. * @probe_interval: interval for ratectrl to probe for other rates
  134. * @prev_data_rix: rate idx of last data frame
  135. * @ht_cap: HT capabilities
  136. * @single_stream: When TRUE, only single TX stream possible
  137. * @neg_rates: Negotatied rates
  138. * @neg_ht_rates: Negotiated HT rates
  139. */
  140. struct ath_rate_priv {
  141. int8_t rssi_last;
  142. int8_t rssi_last_lookup;
  143. int8_t rssi_last_prev;
  144. int8_t rssi_last_prev2;
  145. int32_t rssi_sum_cnt;
  146. int32_t rssi_sum_rate;
  147. int32_t rssi_sum;
  148. u8 rate_table_size;
  149. u8 probe_rate;
  150. u8 hw_maxretry_pktcnt;
  151. u8 max_valid_rate;
  152. u8 valid_rate_index[RATE_TABLE_SIZE];
  153. u8 ht_cap;
  154. u8 single_stream;
  155. u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
  156. u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
  157. u8 rc_phy_mode;
  158. u8 rate_max_phy;
  159. u32 rssi_time;
  160. u32 rssi_down_time;
  161. u32 probe_time;
  162. u32 per_down_time;
  163. u32 probe_interval;
  164. u32 prev_data_rix;
  165. u32 tx_triglevel_max;
  166. struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE];
  167. struct ath_rateset neg_rates;
  168. struct ath_rateset neg_ht_rates;
  169. struct ath_rate_softc *asc;
  170. };
  171. struct ath_tx_info_priv {
  172. struct ath_tx_status tx;
  173. int n_frames;
  174. int n_bad_frames;
  175. bool update_rc;
  176. };
  177. #define ATH_TX_INFO_PRIV(tx_info) \
  178. ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
  179. void ath_rate_attach(struct ath_softc *sc);
  180. u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
  181. int ath_rate_control_register(void);
  182. void ath_rate_control_unregister(void);
  183. #endif /* RC_H */