rate.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef _BRCM_RATE_H_
  17. #define _BRCM_RATE_H_
  18. #include "types.h"
  19. #include "d11.h"
  20. #include "phy_hal.h"
  21. extern const u8 rate_info[];
  22. extern const struct brcms_c_rateset cck_ofdm_mimo_rates;
  23. extern const struct brcms_c_rateset ofdm_mimo_rates;
  24. extern const struct brcms_c_rateset cck_ofdm_rates;
  25. extern const struct brcms_c_rateset ofdm_rates;
  26. extern const struct brcms_c_rateset cck_rates;
  27. extern const struct brcms_c_rateset gphy_legacy_rates;
  28. extern const struct brcms_c_rateset rate_limit_1_2;
  29. struct brcms_mcs_info {
  30. /* phy rate in kbps [20Mhz] */
  31. u32 phy_rate_20;
  32. /* phy rate in kbps [40Mhz] */
  33. u32 phy_rate_40;
  34. /* phy rate in kbps [20Mhz] with SGI */
  35. u32 phy_rate_20_sgi;
  36. /* phy rate in kbps [40Mhz] with SGI */
  37. u32 phy_rate_40_sgi;
  38. /* phy ctl byte 3, code rate, modulation type, # of streams */
  39. u8 tx_phy_ctl3;
  40. /* matching legacy ofdm rate in 500bkps */
  41. u8 leg_ofdm;
  42. };
  43. #define BRCMS_MAXMCS 32 /* max valid mcs index */
  44. #define MCS_TABLE_SIZE 33 /* Number of mcs entries in the table */
  45. extern const struct brcms_mcs_info mcs_table[];
  46. #define MCS_TXS_MASK 0xc0 /* num tx streams - 1 bit mask */
  47. #define MCS_TXS_SHIFT 6 /* num tx streams - 1 bit shift */
  48. /* returns num tx streams - 1 */
  49. static inline u8 mcs_2_txstreams(u8 mcs)
  50. {
  51. return (mcs_table[mcs].tx_phy_ctl3 & MCS_TXS_MASK) >> MCS_TXS_SHIFT;
  52. }
  53. static inline uint mcs_2_rate(u8 mcs, bool is40, bool sgi)
  54. {
  55. if (sgi) {
  56. if (is40)
  57. return mcs_table[mcs].phy_rate_40_sgi;
  58. return mcs_table[mcs].phy_rate_20_sgi;
  59. }
  60. if (is40)
  61. return mcs_table[mcs].phy_rate_40;
  62. return mcs_table[mcs].phy_rate_20;
  63. }
  64. /* Macro to use the rate_info table */
  65. #define BRCMS_RATE_MASK_FULL 0xff /* Rate value mask with basic rate flag */
  66. /*
  67. * rate spec : holds rate and mode specific information required to generate a
  68. * tx frame. Legacy CCK and OFDM information is held in the same manner as was
  69. * done in the past (in the lower byte) the upper 3 bytes primarily hold MIMO
  70. * specific information
  71. */
  72. /* rate spec bit fields */
  73. /* Either 500Kbps units or MIMO MCS idx */
  74. #define RSPEC_RATE_MASK 0x0000007F
  75. /* mimo MCS is stored in RSPEC_RATE_MASK */
  76. #define RSPEC_MIMORATE 0x08000000
  77. /* mimo bw mask */
  78. #define RSPEC_BW_MASK 0x00000700
  79. /* mimo bw shift */
  80. #define RSPEC_BW_SHIFT 8
  81. /* mimo Space/Time/Frequency mode mask */
  82. #define RSPEC_STF_MASK 0x00003800
  83. /* mimo Space/Time/Frequency mode shift */
  84. #define RSPEC_STF_SHIFT 11
  85. /* mimo coding type mask */
  86. #define RSPEC_CT_MASK 0x0000C000
  87. /* mimo coding type shift */
  88. #define RSPEC_CT_SHIFT 14
  89. /* mimo num STC streams per PLCP defn. */
  90. #define RSPEC_STC_MASK 0x00300000
  91. /* mimo num STC streams per PLCP defn. */
  92. #define RSPEC_STC_SHIFT 20
  93. /* mimo bit indicates adv coding in use */
  94. #define RSPEC_LDPC_CODING 0x00400000
  95. /* mimo bit indicates short GI in use */
  96. #define RSPEC_SHORT_GI 0x00800000
  97. /* bit indicates override both rate & mode */
  98. #define RSPEC_OVERRIDE 0x80000000
  99. /* bit indicates override rate only */
  100. #define RSPEC_OVERRIDE_MCS_ONLY 0x40000000
  101. static inline bool rspec_active(u32 rspec)
  102. {
  103. return rspec & (RSPEC_RATE_MASK | RSPEC_MIMORATE);
  104. }
  105. static inline u8 rspec_phytxbyte2(u32 rspec)
  106. {
  107. return (rspec & 0xff00) >> 8;
  108. }
  109. static inline u32 rspec_get_bw(u32 rspec)
  110. {
  111. return (rspec & RSPEC_BW_MASK) >> RSPEC_BW_SHIFT;
  112. }
  113. static inline bool rspec_issgi(u32 rspec)
  114. {
  115. return (rspec & RSPEC_SHORT_GI) == RSPEC_SHORT_GI;
  116. }
  117. static inline bool rspec_is40mhz(u32 rspec)
  118. {
  119. u32 bw = rspec_get_bw(rspec);
  120. return bw == PHY_TXC1_BW_40MHZ || bw == PHY_TXC1_BW_40MHZ_DUP;
  121. }
  122. static inline uint rspec2rate(u32 rspec)
  123. {
  124. if (rspec & RSPEC_MIMORATE)
  125. return mcs_2_rate(rspec & RSPEC_RATE_MASK, rspec_is40mhz(rspec),
  126. rspec_issgi(rspec));
  127. return rspec & RSPEC_RATE_MASK;
  128. }
  129. static inline u8 rspec_mimoplcp3(u32 rspec)
  130. {
  131. return (rspec & 0xf00000) >> 16;
  132. }
  133. static inline bool plcp3_issgi(u8 plcp)
  134. {
  135. return (plcp & (RSPEC_SHORT_GI >> 16)) != 0;
  136. }
  137. static inline uint rspec_stc(u32 rspec)
  138. {
  139. return (rspec & RSPEC_STC_MASK) >> RSPEC_STC_SHIFT;
  140. }
  141. static inline uint rspec_stf(u32 rspec)
  142. {
  143. return (rspec & RSPEC_STF_MASK) >> RSPEC_STF_SHIFT;
  144. }
  145. static inline bool is_mcs_rate(u32 ratespec)
  146. {
  147. return (ratespec & RSPEC_MIMORATE) != 0;
  148. }
  149. static inline bool is_ofdm_rate(u32 ratespec)
  150. {
  151. return !is_mcs_rate(ratespec) &&
  152. (rate_info[ratespec & RSPEC_RATE_MASK] & BRCMS_RATE_FLAG);
  153. }
  154. static inline bool is_cck_rate(u32 ratespec)
  155. {
  156. u32 rate = (ratespec & BRCMS_RATE_MASK);
  157. return !is_mcs_rate(ratespec) && (
  158. rate == BRCM_RATE_1M || rate == BRCM_RATE_2M ||
  159. rate == BRCM_RATE_5M5 || rate == BRCM_RATE_11M);
  160. }
  161. static inline bool is_single_stream(u8 mcs)
  162. {
  163. return mcs <= HIGHEST_SINGLE_STREAM_MCS || mcs == 32;
  164. }
  165. static inline u8 cck_rspec(u8 cck)
  166. {
  167. return cck & RSPEC_RATE_MASK;
  168. }
  169. /* Convert encoded rate value in plcp header to numerical rates in 500 KHz
  170. * increments */
  171. static inline u8 ofdm_phy2mac_rate(u8 rlpt)
  172. {
  173. return wlc_phy_get_ofdm_rate_lookup()[rlpt & 0x7];
  174. }
  175. static inline u8 cck_phy2mac_rate(u8 signal)
  176. {
  177. return signal/5;
  178. }
  179. /* Rates specified in brcms_c_rateset_filter() */
  180. #define BRCMS_RATES_CCK_OFDM 0
  181. #define BRCMS_RATES_CCK 1
  182. #define BRCMS_RATES_OFDM 2
  183. /* sanitize, and sort a rateset with the basic bit(s) preserved, validate
  184. * rateset */
  185. bool brcms_c_rate_hwrs_filter_sort_validate(struct brcms_c_rateset *rs,
  186. const struct brcms_c_rateset *hw_rs,
  187. bool check_brate, u8 txstreams);
  188. /* copy rateset src to dst as-is (no masking or sorting) */
  189. void brcms_c_rateset_copy(const struct brcms_c_rateset *src,
  190. struct brcms_c_rateset *dst);
  191. /* would be nice to have these documented ... */
  192. u32 brcms_c_compute_rspec(struct d11rxhdr *rxh, u8 *plcp);
  193. void brcms_c_rateset_filter(struct brcms_c_rateset *src,
  194. struct brcms_c_rateset *dst, bool basic_only,
  195. u8 rates, uint xmask, bool mcsallow);
  196. void brcms_c_rateset_default(struct brcms_c_rateset *rs_tgt,
  197. const struct brcms_c_rateset *rs_hw, uint phy_type,
  198. int bandtype, bool cck_only, uint rate_mask,
  199. bool mcsallow, u8 bw, u8 txstreams);
  200. s16 brcms_c_rate_legacy_phyctl(uint rate);
  201. void brcms_c_rateset_mcs_upd(struct brcms_c_rateset *rs, u8 txstreams);
  202. void brcms_c_rateset_mcs_clear(struct brcms_c_rateset *rateset);
  203. void brcms_c_rateset_mcs_build(struct brcms_c_rateset *rateset, u8 txstreams);
  204. void brcms_c_rateset_bw_mcs_filter(struct brcms_c_rateset *rateset, u8 bw);
  205. #endif /* _BRCM_RATE_H_ */