1 /* 2 * Common OS-independent driver header for rate management. 3 * 4 * Copyright (C) 2020, Broadcom. 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions of 16 * the license of that module. An independent module is a module which is not 17 * derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * 21 * <<Broadcom-WL-IPTag/Dual:>> 22 */ 23 24 #ifndef _bcmwifi_rspec_h_ 25 #define _bcmwifi_rspec_h_ 26 27 #include <typedefs.h> 28 29 /** 30 * =================================================================================== 31 * rate spec : holds rate and mode specific information required to generate a tx frame. 32 * Legacy CCK and OFDM information is held in the same manner as was done in the past. 33 * (in the lower byte) the upper 3 bytes primarily hold MIMO specific information 34 * =================================================================================== 35 */ 36 typedef uint32 ratespec_t; 37 38 /* Rate spec. definitions */ 39 /* for WL_RSPEC_ENCODING field >= WL_RSPEC_ENCODING_HE, backward compatible */ 40 #define WL_RSPEC_RATE_MASK 0x000000FFu /**< Legacy rate or MCS or MCS + NSS */ 41 #define WL_RSPEC_TXEXP_MASK 0x00000300u /**< Tx chain expansion beyond Nsts */ 42 #define WL_RSPEC_TXEXP_SHIFT 8u 43 #define WL_RSPEC_HE_GI_MASK 0x00000C00u /* HE GI indices */ 44 #define WL_RSPEC_HE_GI_SHIFT 10u 45 #define WL_RSPEC_ER_MASK 0x0000C000u /**< Range extension mask */ 46 #define WL_RSPEC_ER_SHIFT 14u 47 #define WL_RSPEC_ER_TONE_MASK 0x00004000u /**< Range extension tone config */ 48 #define WL_RSPEC_ER_TONE_SHIFT 14u 49 #define WL_RSPEC_ER_ENAB_MASK 0x00008000u /**< Range extension enable */ 50 #define WL_RSPEC_ER_ENAB_SHIFT 15u 51 #define WL_RSPEC_BW_MASK 0x00070000u /**< Band width */ 52 #define WL_RSPEC_BW_SHIFT 16u 53 #define WL_RSPEC_DCM 0x00080000u /**< Dual Carrier Modulation */ 54 #define WL_RSPEC_DCM_SHIFT 19u 55 #define WL_RSPEC_STBC 0x00100000u /**< STBC expansion, Nsts = 2 * Nss */ 56 #define WL_RSPEC_TXBF 0x00200000u 57 #define WL_RSPEC_LDPC 0x00400000u 58 #define WL_RSPEC_SGI 0x00800000u 59 #define WL_RSPEC_SHORT_PREAMBLE 0x00800000u /**< DSSS short preable - Encoding 0 */ 60 #ifdef WL11BE 61 #define WL_RSPEC_ENCODING_MASK 0x07000000u /**< Encoding of RSPEC_RATE field */ 62 #else 63 #define WL_RSPEC_ENCODING_MASK 0x03000000u /**< Encoding of RSPEC_RATE field */ 64 #endif 65 #define WL_RSPEC_ENCODING_SHIFT 24u 66 #define WL_RSPEC_OVERRIDE_RATE 0x40000000u /**< override rate only */ 67 #define WL_RSPEC_OVERRIDE_MODE 0x80000000u /**< override both rate & mode */ 68 69 /* ======== RSPEC_HE_GI|RSPEC_SGI fields for HE ======== */ 70 71 /* GI for HE */ 72 #define RSPEC_HE_LTF_GI(rspec) (((rspec) & WL_RSPEC_HE_GI_MASK) >> WL_RSPEC_HE_GI_SHIFT) 73 #define WL_RSPEC_HE_1x_LTF_GI_0_8us (0x0u) 74 #define WL_RSPEC_HE_2x_LTF_GI_0_8us (0x1u) 75 #define WL_RSPEC_HE_2x_LTF_GI_1_6us (0x2u) 76 #define WL_RSPEC_HE_4x_LTF_GI_3_2us (0x3u) 77 #define RSPEC_ISHEGI(rspec) (RSPEC_HE_LTF_GI(rspec) > WL_RSPEC_HE_1x_LTF_GI_0_8us) 78 #define HE_GI_TO_RSPEC(gi) (((ratespec_t)(gi) << WL_RSPEC_HE_GI_SHIFT) & WL_RSPEC_HE_GI_MASK) 79 #define HE_GI_TO_RSPEC_SET(rspec, gi) ((rspec & (~WL_RSPEC_HE_GI_MASK)) | \ 80 HE_GI_TO_RSPEC(gi)) 81 82 /* Macros for HE LTF and GI */ 83 #define HE_IS_1X_LTF(gi) ((gi) == WL_RSPEC_HE_1x_LTF_GI_0_8us) 84 #define HE_IS_2X_LTF(gi) (((gi) == WL_RSPEC_HE_2x_LTF_GI_0_8us) || \ 85 ((gi) == WL_RSPEC_HE_2x_LTF_GI_1_6us)) 86 #define HE_IS_4X_LTF(gi) ((gi) == WL_RSPEC_HE_4x_LTF_GI_3_2us) 87 88 #define HE_IS_GI_0_8us(gi) (((gi) == WL_RSPEC_HE_1x_LTF_GI_0_8us) || \ 89 ((gi) == WL_RSPEC_HE_2x_LTF_GI_0_8us)) 90 #define HE_IS_GI_1_6us(gi) ((gi) == WL_RSPEC_HE_2x_LTF_GI_1_6us) 91 #define HE_IS_GI_3_2us(gi) ((gi) == WL_RSPEC_HE_4x_LTF_GI_3_2us) 92 93 /* RSPEC Macros for extracting and using HE-ER and DCM */ 94 #define RSPEC_HE_DCM(rspec) (((rspec) & WL_RSPEC_DCM) >> WL_RSPEC_DCM_SHIFT) 95 #define RSPEC_HE_ER(rspec) (((rspec) & WL_RSPEC_ER_MASK) >> WL_RSPEC_ER_SHIFT) 96 #ifdef WL11AX 97 #define RSPEC_HE_ER_ENAB(rspec) (((rspec) & WL_RSPEC_ER_ENAB_MASK) >> \ 98 WL_RSPEC_ER_ENAB_SHIFT) 99 #else 100 #define RSPEC_HE_ER_ENAB(rspec) FALSE 101 #endif 102 #define RSPEC_HE_ER_TONE(rspec) (((rspec) & WL_RSPEC_ER_TONE_MASK) >> \ 103 WL_RSPEC_ER_TONE_SHIFT) 104 /* ======== RSPEC_RATE field ======== */ 105 106 /* Encoding 0 - legacy rate */ 107 /* DSSS, CCK, and OFDM rates in [500kbps] units */ 108 #define WL_RSPEC_LEGACY_RATE_MASK 0x0000007F 109 #define WLC_RATE_1M 2 110 #define WLC_RATE_2M 4 111 #define WLC_RATE_5M5 11 112 #define WLC_RATE_11M 22 113 #define WLC_RATE_6M 12 114 #define WLC_RATE_9M 18 115 #define WLC_RATE_12M 24 116 #define WLC_RATE_18M 36 117 #define WLC_RATE_24M 48 118 #define WLC_RATE_36M 72 119 #define WLC_RATE_48M 96 120 #define WLC_RATE_54M 108 121 122 /* Encoding 1 - HT MCS */ 123 #define WL_RSPEC_HT_MCS_MASK 0x0000007F /**< HT MCS value mask in rspec */ 124 125 /* Encoding >= 2 */ 126 #define WL_RSPEC_NSS_MCS_MASK 0x000000FF /* NSS & MCS values mask in rspec */ 127 #define WL_RSPEC_MCS_MASK 0x0000000F /* mimo MCS value mask in rspec */ 128 #define WL_RSPEC_NSS_MASK 0x000000F0 /* mimo NSS value mask in rspec */ 129 #define WL_RSPEC_NSS_SHIFT 4 /* mimo NSS value shift in rspec */ 130 131 /* Encoding 2 - VHT MCS + NSS */ 132 #define WL_RSPEC_VHT_MCS_MASK WL_RSPEC_MCS_MASK /**< VHT MCS value mask in rspec */ 133 #define WL_RSPEC_VHT_NSS_MASK WL_RSPEC_NSS_MASK /**< VHT Nss value mask in rspec */ 134 #define WL_RSPEC_VHT_NSS_SHIFT WL_RSPEC_NSS_SHIFT /**< VHT Nss value shift in rspec */ 135 136 /* Encoding 3 - HE MCS + NSS */ 137 #define WL_RSPEC_HE_MCS_MASK WL_RSPEC_MCS_MASK /**< HE MCS value mask in rspec */ 138 #define WL_RSPEC_HE_NSS_MASK WL_RSPEC_NSS_MASK /**< HE Nss value mask in rspec */ 139 #define WL_RSPEC_HE_NSS_SHIFT WL_RSPEC_NSS_SHIFT /**< HE Nss value shift in rpsec */ 140 141 /* Encoding 4 - EHT MCS + NSS */ 142 #define WL_RSPEC_EHT_MCS_MASK WL_RSPEC_MCS_MASK /**< EHT MCS value mask in rspec */ 143 #define WL_RSPEC_EHT_NSS_MASK WL_RSPEC_NSS_MASK /**< EHT Nss value mask in rspec */ 144 #define WL_RSPEC_EHT_NSS_SHIFT WL_RSPEC_NSS_SHIFT /**< EHT Nss value shift in rpsec */ 145 146 /* ======== RSPEC_BW field ======== */ 147 148 #define WL_RSPEC_BW_UNSPECIFIED 0u 149 #define WL_RSPEC_BW_20MHZ 0x00010000u 150 #define WL_RSPEC_BW_40MHZ 0x00020000u 151 #define WL_RSPEC_BW_80MHZ 0x00030000u 152 #define WL_RSPEC_BW_160MHZ 0x00040000u 153 #define WL_RSPEC_BW_240MHZ 0x00050000u 154 #define WL_RSPEC_BW_320MHZ 0x00060000u 155 156 /* ======== RSPEC_ENCODING field ======== */ 157 158 /* NOTE: Assuming the rate field is always NSS+MCS starting from VHT encoding! 159 * Modify/fix RSPEC_ISNSSMCS() macro if above condition changes any time. 160 */ 161 #define WL_RSPEC_ENCODE_RATE 0x00000000u /**< Legacy rate is stored in RSPEC_RATE */ 162 #define WL_RSPEC_ENCODE_HT 0x01000000u /**< HT MCS is stored in RSPEC_RATE */ 163 #define WL_RSPEC_ENCODE_VHT 0x02000000u /**< VHT MCS and NSS are stored in RSPEC_RATE */ 164 #define WL_RSPEC_ENCODE_HE 0x03000000u /**< HE MCS and NSS are stored in RSPEC_RATE */ 165 #define WL_RSPEC_ENCODE_EHT 0x04000000u /**< EHT MCS and NSS are stored in RSPEC_RATE */ 166 167 /** 168 * =============================== 169 * Handy macros to parse rate spec 170 * =============================== 171 */ 172 #define RSPEC_BW(rspec) ((rspec) & WL_RSPEC_BW_MASK) 173 #define RSPEC_IS20MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_20MHZ) 174 #define RSPEC_IS40MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_40MHZ) 175 #define RSPEC_IS80MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_80MHZ) 176 #define RSPEC_IS160MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_160MHZ) 177 #ifdef WL11BE 178 #define RSPEC_IS240MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_240MHZ) 179 #define RSPEC_IS320MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_320MHZ) 180 #else 181 #define RSPEC_IS320MHZ(rspec) (FALSE) 182 #define RSPEC_IS240MHZ(rspec) (FALSE) 183 #endif /* WL11BE */ 184 185 #define RSPEC_ISSGI(rspec) (((rspec) & WL_RSPEC_SGI) != 0) 186 #define RSPEC_ISLDPC(rspec) (((rspec) & WL_RSPEC_LDPC) != 0) 187 #define RSPEC_ISSTBC(rspec) (((rspec) & WL_RSPEC_STBC) != 0) 188 #define RSPEC_ISTXBF(rspec) (((rspec) & WL_RSPEC_TXBF) != 0) 189 190 #define RSPEC_TXEXP(rspec) (((rspec) & WL_RSPEC_TXEXP_MASK) >> WL_RSPEC_TXEXP_SHIFT) 191 192 #define RSPEC_ENCODE(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) >> WL_RSPEC_ENCODING_SHIFT) 193 #define RSPEC_ISLEGACY(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_RATE) 194 195 #define RSPEC_ISCCK(rspec) (RSPEC_ISLEGACY(rspec) && \ 196 (int8)rate_info[(rspec) & WL_RSPEC_LEGACY_RATE_MASK] > 0) 197 #define RSPEC_ISOFDM(rspec) (RSPEC_ISLEGACY(rspec) && \ 198 (int8)rate_info[(rspec) & WL_RSPEC_LEGACY_RATE_MASK] < 0) 199 200 #define RSPEC_ISHT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HT) 201 #define RSPEC_ISVHT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_VHT) 202 #ifdef WL11AX 203 #define RSPEC_ISHE(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HE) 204 #else /* WL11AX */ 205 #define RSPEC_ISHE(rspec) 0 206 #endif /* WL11AX */ 207 #ifdef WL11BE 208 #define RSPEC_ISEHT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_EHT) 209 #else /* WL11BE */ 210 #define RSPEC_ISEHT(rspec) 0 211 #endif /* WL11BE */ 212 213 /* fast check if rate field is NSS+MCS format (starting from VHT ratespec) */ 214 #define RSPEC_ISVHTEXT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) >= WL_RSPEC_ENCODE_VHT) 215 /* fast check if rate field is NSS+MCS format (starting from HE ratespec) */ 216 #define RSPEC_ISHEEXT(rspec) (((rspec) & WL_RSPEC_ENCODING_MASK) >= WL_RSPEC_ENCODE_HE) 217 218 /** 219 * ================================ 220 * Handy macros to create rate spec 221 * ================================ 222 */ 223 /* create ratespecs */ 224 #define LEGACY_RSPEC(rate) (WL_RSPEC_ENCODE_RATE | WL_RSPEC_BW_20MHZ | \ 225 ((rate) & WL_RSPEC_LEGACY_RATE_MASK)) 226 #define CCK_RSPEC(cck) LEGACY_RSPEC(cck) 227 #define OFDM_RSPEC(ofdm) LEGACY_RSPEC(ofdm) 228 #define HT_RSPEC(mcs) (WL_RSPEC_ENCODE_HT | ((mcs) & WL_RSPEC_HT_MCS_MASK)) 229 #define VHT_RSPEC(mcs, nss) (WL_RSPEC_ENCODE_VHT | \ 230 (((nss) << WL_RSPEC_VHT_NSS_SHIFT) & WL_RSPEC_VHT_NSS_MASK) | \ 231 ((mcs) & WL_RSPEC_VHT_MCS_MASK)) 232 #define HE_RSPEC(mcs, nss) (WL_RSPEC_ENCODE_HE | \ 233 (((nss) << WL_RSPEC_HE_NSS_SHIFT) & WL_RSPEC_HE_NSS_MASK) | \ 234 ((mcs) & WL_RSPEC_HE_MCS_MASK)) 235 #define EHT_RSPEC(mcs, nss) (WL_RSPEC_ENCODE_EHT | \ 236 (((nss) << WL_RSPEC_EHT_NSS_SHIFT) & WL_RSPEC_EHT_NSS_MASK) | \ 237 ((mcs) & WL_RSPEC_EHT_MCS_MASK)) 238 239 /** 240 * ================== 241 * Other handy macros 242 * ================== 243 */ 244 /* return rate in unit of Kbps */ 245 #define RSPEC2KBPS(rspec) wf_rspec_to_rate(rspec) 246 247 /* return rate in unit of 500Kbps */ 248 /* works only for legacy rate */ 249 #ifdef BCMDBG 250 #define RSPEC2RATE(rspec) wf_rspec_to_rate_legacy(rspec) 251 #else 252 #define RSPEC2RATE(rspec) ((rspec) & WL_RSPEC_LEGACY_RATE_MASK) 253 #endif 254 255 /** 256 * ================================= 257 * Macros to use the rate_info table 258 * ================================= 259 */ 260 /* phy_rate table index is in [500kbps] units */ 261 #define WLC_MAXRATE 108 /**< in 500kbps units */ 262 extern const uint8 rate_info[]; 263 /* phy_rate table value is encoded */ 264 #define RATE_INFO_OFDM_MASK 0x80 /* ofdm mask */ 265 #define RATE_INFO_RATE_MASK 0x7f /* rate signal index mask */ 266 #define RATE_INFO_M_RATE_MASK 0x0f /* M_RATE_TABLE index mask */ 267 #define RATE_INFO_RATE_ISCCK(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] > 0) 268 #define RATE_INFO_RATE_ISOFDM(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] < 0) 269 270 /** 271 * =================== 272 * function prototypes 273 * =================== 274 */ 275 ratespec_t wf_vht_plcp_to_rspec(uint8 *plcp); 276 ratespec_t wf_he_plcp_to_rspec(uint8 *plcp); 277 ratespec_t wf_eht_plcp_to_rspec(uint8 *plcp); 278 ratespec_t wf_ht_plcp_to_rspec(uint8 *plcp); 279 280 #ifdef BCMDBG 281 uint wf_rspec_to_rate_legacy(ratespec_t rspec); 282 #endif 283 uint wf_rspec_to_rate(ratespec_t rspec); 284 uint wf_rspec_to_rate_rsel(ratespec_t rspec); 285 286 #endif /* _bcmwifi_rspec_h_ */ 287