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