• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Common OS-independent driver header for rate management.
3  *
4  * Copyright (C) 1999-2019, 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
16  * of the license of that module.  An independent module is a module which is
17  * not derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id: bcmwifi_rspec.h 736703 2017-12-18 06:55:37Z $
28  */
29 
30 #ifndef _bcmwifi_rspec_h_
31 #define _bcmwifi_rspec_h_
32 
33 #include <typedefs.h>
34 
35 /**
36  * ===================================================================================
37  * rate spec : holds rate and mode specific information required to generate a
38  * tx frame. Legacy CCK and OFDM information is held in the same manner as was
39  * done in the past. (in the lower byte) the upper 3 bytes primarily hold MIMO
40  * 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                                                \
59     0x00800000 /**< DSSS short preable - Encoding 0 */
60 #define WL_RSPEC_ENCODING_MASK 0x03000000 /**< Encoding of RSPEC_RATE field */
61 #define WL_RSPEC_ENCODING_SHIFT 24
62 
63 #define WL_RSPEC_OVERRIDE_RATE 0x40000000 /**< override rate only */
64 #define WL_RSPEC_OVERRIDE_MODE 0x80000000 /**< override both rate & mode */
65 
66 /* ======== RSPEC_HE_GI|RSPEC_SGI fields for HE ======== */
67 
68 /* GI for HE */
69 #define RSPEC_HE_LTF_GI(rspec)                                                 \
70     (((rspec)&WL_RSPEC_HE_GI_MASK) >> WL_RSPEC_HE_GI_SHIFT)
71 #define WL_RSPEC_HE_1x_LTF_GI_0_8us (0x0)
72 #define WL_RSPEC_HE_2x_LTF_GI_0_8us (0x1)
73 #define WL_RSPEC_HE_2x_LTF_GI_1_6us (0x2)
74 #define WL_RSPEC_HE_4x_LTF_GI_3_2us (0x3)
75 #define RSPEC_ISHEGI(rspec)                                                    \
76     (RSPEC_HE_LTF_GI(rspec) > WL_RSPEC_HE_1x_LTF_GI_0_8us)
77 #define HE_GI_TO_RSPEC(gi)                                                     \
78     (((gi) << WL_RSPEC_HE_GI_SHIFT) & WL_RSPEC_HE_GI_MASK)
79 /* ======== RSPEC_RATE field ======== */
80 
81 /* Encoding 0 - legacy rate */
82 /* DSSS, CCK, and OFDM rates in [500kbps] units */
83 #define WL_RSPEC_LEGACY_RATE_MASK 0x0000007F
84 #define WLC_RATE_1M 2
85 #define WLC_RATE_2M 4
86 #define WLC_RATE_5M5 11
87 #define WLC_RATE_11M 22
88 #define WLC_RATE_6M 12
89 #define WLC_RATE_9M 18
90 #define WLC_RATE_12M 24
91 #define WLC_RATE_18M 36
92 #define WLC_RATE_24M 48
93 #define WLC_RATE_36M 72
94 #define WLC_RATE_48M 96
95 #define WLC_RATE_54M 108
96 
97 /* Encoding 1 - HT MCS */
98 #define WL_RSPEC_HT_MCS_MASK 0x0000007F /**< HT MCS value mask in rspec */
99 
100 /* Encoding 2 - VHT MCS + NSS */
101 #define WL_RSPEC_VHT_MCS_MASK 0x0000000F /**< VHT MCS value mask in rspec */
102 #define WL_RSPEC_VHT_NSS_MASK 0x000000F0 /**< VHT Nss value mask in rspec */
103 #define WL_RSPEC_VHT_NSS_SHIFT 4         /**< VHT Nss value shift in rspec */
104 
105 /* Encoding 3 - HE MCS + NSS */
106 #define WL_RSPEC_HE_MCS_MASK 0x0000000F /**< HE MCS value mask in rspec */
107 #define WL_RSPEC_HE_NSS_MASK 0x000000F0 /**< HE Nss value mask in rspec */
108 #define WL_RSPEC_HE_NSS_SHIFT 4         /**< HE Nss value shift in rpsec */
109 
110 /* ======== RSPEC_BW field ======== */
111 
112 #define WL_RSPEC_BW_UNSPECIFIED 0
113 #define WL_RSPEC_BW_20MHZ 0x00010000
114 #define WL_RSPEC_BW_40MHZ 0x00020000
115 #define WL_RSPEC_BW_80MHZ 0x00030000
116 #define WL_RSPEC_BW_160MHZ 0x00040000
117 
118 /* ======== RSPEC_ENCODING field ======== */
119 
120 #define WL_RSPEC_ENCODE_RATE                                                   \
121     0x00000000 /**< Legacy rate is stored in RSPEC_RATE */
122 #define WL_RSPEC_ENCODE_HT 0x01000000 /**< HT MCS is stored in RSPEC_RATE */
123 #define WL_RSPEC_ENCODE_VHT                                                    \
124     0x02000000 /**< VHT MCS and NSS are stored in RSPEC_RATE */
125 #define WL_RSPEC_ENCODE_HE                                                     \
126     0x03000000 /**< HE MCS and NSS are stored in RSPEC_RATE */
127 
128 /**
129  * ===============================
130  * Handy macros to parse rate spec
131  * ===============================
132  */
133 #define RSPEC_BW(rspec) ((rspec)&WL_RSPEC_BW_MASK)
134 #define RSPEC_IS20MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_20MHZ)
135 #define RSPEC_IS40MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_40MHZ)
136 #define RSPEC_IS80MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_80MHZ)
137 #define RSPEC_IS160MHZ(rspec) (RSPEC_BW(rspec) == WL_RSPEC_BW_160MHZ)
138 
139 #define RSPEC_ISSGI(rspec) (((rspec)&WL_RSPEC_SGI) != 0)
140 #define RSPEC_ISLDPC(rspec) (((rspec)&WL_RSPEC_LDPC) != 0)
141 #define RSPEC_ISSTBC(rspec) (((rspec)&WL_RSPEC_STBC) != 0)
142 #define RSPEC_ISTXBF(rspec) (((rspec)&WL_RSPEC_TXBF) != 0)
143 
144 #define RSPEC_TXEXP(rspec)                                                     \
145     (((rspec)&WL_RSPEC_TXEXP_MASK) >> WL_RSPEC_TXEXP_SHIFT)
146 
147 #define RSPEC_ENCODE(rspec)                                                    \
148     (((rspec)&WL_RSPEC_ENCODING_MASK) >> WL_RSPEC_ENCODING_SHIFT)
149 #define RSPEC_ISLEGACY(rspec)                                                  \
150     (((rspec)&WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_RATE)
151 
152 #define RSPEC_ISCCK(rspec)                                                     \
153     (RSPEC_ISLEGACY(rspec) &&                                                  \
154      (int8)rate_info[(rspec)&WL_RSPEC_LEGACY_RATE_MASK] > 0)
155 #define RSPEC_ISOFDM(rspec)                                                    \
156     (RSPEC_ISLEGACY(rspec) &&                                                  \
157      (int8)rate_info[(rspec)&WL_RSPEC_LEGACY_RATE_MASK] < 0)
158 
159 #define RSPEC_ISHT(rspec)                                                      \
160     (((rspec)&WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HT)
161 #ifdef WL11AC
162 #define RSPEC_ISVHT(rspec)                                                     \
163     (((rspec)&WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_VHT)
164 #else /* WL11AC */
165 #define RSPEC_ISVHT(rspec) 0
166 #endif /* WL11AC */
167 #ifdef WL11AX
168 #define RSPEC_ISHE(rspec)                                                      \
169     (((rspec)&WL_RSPEC_ENCODING_MASK) == WL_RSPEC_ENCODE_HE)
170 #else /* WL11AX */
171 #define RSPEC_ISHE(rspec) 0
172 #endif /* WL11AX */
173 
174 /**
175  * ================================
176  * Handy macros to create rate spec
177  * ================================
178  */
179 /* create ratespecs */
180 #define LEGACY_RSPEC(rate)                                                     \
181     (WL_RSPEC_ENCODE_RATE | WL_RSPEC_BW_20MHZ |                                \
182      ((rate)&WL_RSPEC_LEGACY_RATE_MASK))
183 #define CCK_RSPEC(cck) LEGACY_RSPEC(cck)
184 #define OFDM_RSPEC(ofdm) LEGACY_RSPEC(ofdm)
185 #define HT_RSPEC(mcs) (WL_RSPEC_ENCODE_HT | ((mcs)&WL_RSPEC_HT_MCS_MASK))
186 #define VHT_RSPEC(mcs, nss)                                                    \
187     (WL_RSPEC_ENCODE_VHT |                                                     \
188      (((nss) << WL_RSPEC_VHT_NSS_SHIFT) & WL_RSPEC_VHT_NSS_MASK) |             \
189      ((mcs)&WL_RSPEC_VHT_MCS_MASK))
190 #define HE_RSPEC(mcs, nss)                                                     \
191     (WL_RSPEC_ENCODE_HE |                                                      \
192      (((nss) << WL_RSPEC_HE_NSS_SHIFT) & WL_RSPEC_HE_NSS_MASK) |               \
193      ((mcs)&WL_RSPEC_HE_MCS_MASK))
194 
195 /**
196  * ==================
197  * Other handy macros
198  * ==================
199  */
200 
201 /* return rate in unit of Kbps */
202 #define RSPEC2KBPS(rspec) wf_rspec_to_rate(rspec)
203 
204 /* return rate in unit of 500Kbps */
205 #define RSPEC2RATE(rspec) ((rspec)&WL_RSPEC_LEGACY_RATE_MASK)
206 
207 /**
208  * =================================
209  * Macros to use the rate_info table
210  * =================================
211  */
212 /* phy_rate table index is in [500kbps] units */
213 #define WLC_MAXRATE 108 /**< in 500kbps units */
214 extern const uint8 rate_info[];
215 /* phy_rate table value is encoded */
216 #define RATE_INFO_OFDM_MASK 0x80   /* ofdm mask */
217 #define RATE_INFO_RATE_MASK 0x7f   /* rate signal index mask */
218 #define RATE_INFO_M_RATE_MASK 0x0f /* M_RATE_TABLE index mask */
219 #define RATE_INFO_RATE_ISCCK(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] > 0)
220 #define RATE_INFO_RATE_ISOFDM(r) ((r) <= WLC_MAXRATE && (int8)rate_info[r] < 0)
221 
222 /**
223  * ===================
224  * function prototypes
225  * ===================
226  */
227 ratespec_t wf_vht_plcp_to_rspec(uint8 *plcp);
228 ratespec_t wf_he_plcp_to_rspec(uint8 *plcp);
229 uint wf_rspec_to_rate(ratespec_t rspec);
230 
231 #endif /* _bcmwifi_rspec_h_ */
232