bcmwifi_rspec.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Common OS-independent driver header for rate management.
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: bcmwifi_rspec.h 691138 2018-06-01 01:34:03Z $
  30. */
  31. #ifndef _bcmwifi_rspec_h_
  32. #define _bcmwifi_rspec_h_
  33. #include <typedefs.h>
  34. /**
  35. * ===================================================================================
  36. * rate spec : holds rate and mode specific information required to generate a tx frame.
  37. * Legacy CCK and OFDM information is held in the same manner as was done in the past.
  38. * (in the lower byte) the upper 3 bytes primarily hold MIMO specific information
  39. * ===================================================================================
  40. */
  41. typedef uint32 ratespec_t;
  42. /* Rate spec. definitions */
  43. #define WL_RSPEC_RATE_MASK 0x000000FF /**< Legacy rate or MCS or MCS + NSS */
  44. #define WL_RSPEC_TXEXP_MASK 0x00000300 /**< Tx chain expansion beyond Nsts */
  45. #define WL_RSPEC_TXEXP_SHIFT 8
  46. #define WL_RSPEC_HE_GI_MASK 0x00000C00 /* HE GI indices */
  47. #define WL_RSPEC_HE_GI_SHIFT 10
  48. #define WL_RSPEC_BW_MASK 0x00070000 /**< Band width */
  49. #define WL_RSPEC_BW_SHIFT 16
  50. #define WL_RSPEC_DCM 0x00080000 /**< Dual Carrier Modulation */
  51. #define WL_RSPEC_STBC 0x00100000 /**< STBC expansion, Nsts = 2 * Nss */
  52. #define WL_RSPEC_TXBF 0x00200000
  53. #define WL_RSPEC_LDPC 0x00400000
  54. #define WL_RSPEC_SGI 0x00800000
  55. #define WL_RSPEC_SHORT_PREAMBLE 0x00800000 /**< DSSS short preable - Encoding 0 */
  56. #define WL_RSPEC_ENCODING_MASK 0x03000000 /**< Encoding of RSPEC_RATE field */
  57. #define WL_RSPEC_ENCODING_SHIFT 24
  58. #define WL_RSPEC_OVERRIDE_RATE 0x40000000 /**< override rate only */
  59. #define WL_RSPEC_OVERRIDE_MODE 0x80000000 /**< override both rate & mode */
  60. /* ======== RSPEC_HE_GI|RSPEC_SGI fields for HE ======== */
  61. /* GI for HE */
  62. #define RSPEC_HE_LTF_GI(rspec) (((rspec) & WL_RSPEC_HE_GI_MASK) >> WL_RSPEC_HE_GI_SHIFT)
  63. #define WL_RSPEC_HE_1x_LTF_GI_0_8us (0x0)
  64. #define WL_RSPEC_HE_2x_LTF_GI_0_8us (0x1)
  65. #define WL_RSPEC_HE_2x_LTF_GI_1_6us (0x2)
  66. #define WL_RSPEC_HE_4x_LTF_GI_3_2us (0x3)
  67. #define RSPEC_ISHEGI(rspec) (RSPEC_HE_LTF_GI(rspec) > WL_RSPEC_HE_1x_LTF_GI_0_8us)
  68. #define HE_GI_TO_RSPEC(gi) (((gi) << WL_RSPEC_HE_GI_SHIFT) & WL_RSPEC_HE_GI_MASK)
  69. /* ======== RSPEC_RATE field ======== */
  70. /* Encoding 0 - legacy rate */
  71. /* DSSS, CCK, and OFDM rates in [500kbps] units */
  72. #define WL_RSPEC_LEGACY_RATE_MASK 0x0000007F
  73. #define WLC_RATE_1M 2
  74. #define WLC_RATE_2M 4
  75. #define WLC_RATE_5M5 11
  76. #define WLC_RATE_11M 22
  77. #define WLC_RATE_6M 12
  78. #define WLC_RATE_9M 18
  79. #define WLC_RATE_12M 24
  80. #define WLC_RATE_18M 36
  81. #define WLC_RATE_24M 48
  82. #define WLC_RATE_36M 72
  83. #define WLC_RATE_48M 96
  84. #define WLC_RATE_54M 108
  85. /* Encoding 1 - HT MCS */
  86. #define WL_RSPEC_HT_MCS_MASK 0x0000007F /**< HT MCS value mask in rspec */
  87. /* Encoding 2 - VHT MCS + NSS */
  88. #define WL_RSPEC_VHT_MCS_MASK 0x0000000F /**< VHT MCS value mask in rspec */
  89. #define WL_RSPEC_VHT_NSS_MASK 0x000000F0 /**< VHT Nss value mask in rspec */
  90. #define WL_RSPEC_VHT_NSS_SHIFT 4 /**< VHT Nss value shift in rspec */
  91. /* Encoding 3 - HE MCS + NSS */
  92. #define WL_RSPEC_HE_MCS_MASK 0x0000000F /**< HE MCS value mask in rspec */
  93. #define WL_RSPEC_HE_NSS_MASK 0x000000F0 /**< HE Nss value mask in rspec */
  94. #define WL_RSPEC_HE_NSS_SHIFT 4 /**< HE Nss value shift in rpsec */
  95. /* ======== RSPEC_BW field ======== */
  96. #define WL_RSPEC_BW_UNSPECIFIED 0
  97. #define WL_RSPEC_BW_20MHZ 0x00010000
  98. #define WL_RSPEC_BW_40MHZ 0x00020000
  99. #define WL_RSPEC_BW_80MHZ 0x00030000
  100. #define WL_RSPEC_BW_160MHZ 0x00040000
  101. /* ======== RSPEC_ENCODING field ======== */
  102. #define WL_RSPEC_ENCODE_RATE 0x00000000 /**< Legacy rate is stored in RSPEC_RATE */
  103. #define WL_RSPEC_ENCODE_HT 0x01000000 /**< HT MCS is stored in RSPEC_RATE */
  104. #define WL_RSPEC_ENCODE_VHT 0x02000000 /**< VHT MCS and NSS are stored in RSPEC_RATE */
  105. #define WL_RSPEC_ENCODE_HE 0x03000000 /**< HE MCS and NSS are stored in RSPEC_RATE */
  106. /**
  107. * ===============================
  108. * Handy macros to parse rate spec
  109. * ===============================
  110. */
  111. #define RSPEC_BW(rspec) ((rspec) & WL_RSPEC_BW_MASK)
  112. #define RSPEC_IS20MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_20MHZ)
  113. #define RSPEC_IS40MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_40MHZ)
  114. #define RSPEC_IS80MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_80MHZ)
  115. #define RSPEC_IS160MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_160MHZ)
  116. #define RSPEC_ISSGI(rspec) (((rspec) & WL_RSPEC_SGI) != 0)
  117. #define RSPEC_ISLDPC(rspec) (((rspec) & WL_RSPEC_LDPC) != 0)
  118. #define RSPEC_ISSTBC(rspec) (((rspec) & WL_RSPEC_STBC) != 0)
  119. #define RSPEC_ISTXBF(rspec) (((rspec) & WL_RSPEC_TXBF) != 0)
  120. #define RSPEC_TXEXP(rspec) (((rspec) & WL_RSPEC_TXEXP_MASK) >> WL_RSPEC_TXEXP_SHIFT)
  121. #define RSPEC_ENCODE(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) >> WL_RSPEC_ENCODING_SHIFT)
  122. #define RSPEC_ISLEGACY(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_RATE)
  123. #define RSPEC_ISCCK(rspec) (RSPEC_ISLEGACY(rspec) && \
  124. (int8)rate_info[(rspec) & WL_RSPEC_LEGACY_RATE_MASK] > 0)
  125. #define RSPEC_ISOFDM(rspec) (RSPEC_ISLEGACY(rspec) && \
  126. (int8)rate_info[(rspec) & WL_RSPEC_LEGACY_RATE_MASK] < 0)
  127. #define RSPEC_ISHT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HT)
  128. #ifdef WL11AC
  129. #define RSPEC_ISVHT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_VHT)
  130. #else /* WL11AC */
  131. #define RSPEC_ISVHT(rspec) 0
  132. #endif /* WL11AC */
  133. #ifdef WL11AX
  134. #define RSPEC_ISHE(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HE)
  135. #else /* WL11AX */
  136. #define RSPEC_ISHE(rspec) 0
  137. #endif /* WL11AX */
  138. /**
  139. * ================================
  140. * Handy macros to create rate spec
  141. * ================================
  142. */
  143. /* create ratespecs */
  144. #define LEGACY_RSPEC(rate) (WL_RSPEC_ENCODE_RATE | WL_RSPEC_BW_20MHZ | \
  145. ((rate) & WL_RSPEC_LEGACY_RATE_MASK))
  146. #define CCK_RSPEC(cck) LEGACY_RSPEC(cck)
  147. #define OFDM_RSPEC(ofdm) LEGACY_RSPEC(ofdm)
  148. #define HT_RSPEC(mcs) (WL_RSPEC_ENCODE_HT | ((mcs) & WL_RSPEC_HT_MCS_MASK))
  149. #define VHT_RSPEC(mcs, nss) (WL_RSPEC_ENCODE_VHT | \
  150. (((nss) << WL_RSPEC_VHT_NSS_SHIFT) & WL_RSPEC_VHT_NSS_MASK) | \
  151. ((mcs) & WL_RSPEC_VHT_MCS_MASK))
  152. #define HE_RSPEC(mcs, nss) (WL_RSPEC_ENCODE_HE | \
  153. (((nss) << WL_RSPEC_HE_NSS_SHIFT) & WL_RSPEC_HE_NSS_MASK) | \
  154. ((mcs) & WL_RSPEC_HE_MCS_MASK))
  155. /**
  156. * ==================
  157. * Other handy macros
  158. * ==================
  159. */
  160. /* return rate in unit of Kbps */
  161. #define RSPEC2KBPS(rspec) wf_rspec_to_rate(rspec)
  162. /* return rate in unit of 500Kbps */
  163. #define RSPEC2RATE(rspec) ((rspec) & WL_RSPEC_LEGACY_RATE_MASK)
  164. /**
  165. * =================================
  166. * Macros to use the rate_info table
  167. * =================================
  168. */
  169. /* phy_rate table index is in [500kbps] units */
  170. #define WLC_MAXRATE 108 /**< in 500kbps units */
  171. extern const uint8 rate_info[];
  172. /* phy_rate table value is encoded */
  173. #define RATE_INFO_OFDM_MASK 0x80 /* ofdm mask */
  174. #define RATE_INFO_RATE_MASK 0x7f /* rate signal index mask */
  175. #define RATE_INFO_M_RATE_MASK 0x0f /* M_RATE_TABLE index mask */
  176. #define RATE_INFO_RATE_ISCCK(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] > 0)
  177. #define RATE_INFO_RATE_ISOFDM(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] < 0)
  178. /**
  179. * ===================
  180. * function prototypes
  181. * ===================
  182. */
  183. ratespec_t wf_vht_plcp_to_rspec(uint8 *plcp);
  184. ratespec_t wf_he_plcp_to_rspec(uint8 *plcp);
  185. uint wf_rspec_to_rate(ratespec_t rspec);
  186. #endif /* _bcmwifi_rspec_h_ */