xref: /wlan-driver/qca-wifi-host-cmn/dp/cmn_dp_api/dp_ratetable.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _DP_RATES_H_
21 #define _DP_RATES_H_
22 
23 #define CMN_DP_ASSERT(__bool)
24 
25 /*
26  * Modes Types
27  */
28 enum CMN_MODE_TYPES {
29 	CMN_IEEE80211_MODE_INVALID = 0,
30 	CMN_IEEE80211_MODE_A,
31 	CMN_IEEE80211_MODE_B,
32 	CMN_IEEE80211_MODE_G,
33 	CMN_IEEE80211_MODE_TURBO,
34 	CMN_IEEE80211_MODE_NA,
35 	CMN_IEEE80211_MODE_NG,
36 	CMN_IEEE80211_MODE_N,
37 	CMN_IEEE80211_MODE_AC,
38 	CMN_IEEE80211_MODE_AXA,
39 	CMN_IEEE80211_MODE_AXG,
40 	CMN_IEEE80211_MODE_AX,
41 #ifdef WLAN_FEATURE_11BE
42 	CMN_IEEE80211_MODE_BEA,
43 	CMN_IEEE80211_MODE_BEG,
44 #endif
45 	CMN_IEEE80211_MODE_MAX
46 };
47 
48 #define NUM_SPATIAL_STREAMS 8
49 #define MAX_SPATIAL_STREAMS_SUPPORTED_AT_160MHZ 4
50 #define VHT_EXTRA_MCS_SUPPORT
51 #define CONFIG_160MHZ_SUPPORT 1
52 #define NUM_HT_MCS 8
53 #define NUM_VHT_MCS 12
54 
55 #define NUM_HE_MCS 14
56 #ifdef WLAN_FEATURE_11BE
57 #define NUM_EHT_MCS 16
58 #endif
59 
60 #define NUM_SPATIAL_STREAM 4
61 #define NUM_SPATIAL_STREAMS 8
62 #define WHAL_160MHZ_SUPPORT 1
63 #define MAX_SPATIAL_STREAMS_SUPPORTED_AT_160MHZ 4
64 #define RT_GET_RT(_rt)		    ((const struct DP_CMN_RATE_TABLE *)(_rt))
65 #define RT_GET_INFO(_rt, _index)	    RT_GET_RT(_rt)->info[(_index)]
66 #define RT_GET_RAW_KBPS(_rt, _index) \
67 	(RT_GET_INFO(_rt, (_index)).ratekbps)
68 #define RT_GET_SGI_KBPS(_rt, _index) \
69 	(RT_GET_INFO(_rt, (_index)).ratekbpssgi)
70 
71 #define HW_RATECODE_CCK_SHORT_PREAM_MASK  0x4
72 #define RT_INVALID_INDEX (0xff)
73 /* pow2 to optimize out * and / */
74 #define DP_ATH_RATE_EP_MULTIPLIER     BIT(7)
75 #define DP_ATH_EP_MUL(a, b)	      ((a) * (b))
76 #define DP_ATH_RATE_LPF_LEN	      10	  /* Low pass filter length
77 						   * for averaging rates
78 						   */
79 #define DUMMY_MARKER	  0
80 #define DP_ATH_RATE_IN(c)  (DP_ATH_EP_MUL((c), DP_ATH_RATE_EP_MULTIPLIER))
81 
dp_ath_rate_lpf(uint64_t _d,int _e)82 static inline int dp_ath_rate_lpf(uint64_t _d, int _e)
83 {
84 	_e = DP_ATH_RATE_IN((_e));
85 	return (((_d) != DUMMY_MARKER) ? ((((_d) << 3) + (_e) - (_d)) >> 3) :
86 			(_e));
87 }
88 
dp_ath_rate_out(uint64_t _i)89 static inline int dp_ath_rate_out(uint64_t _i)
90 {
91 	int _mul = DP_ATH_RATE_EP_MULTIPLIER;
92 
93 	return (((_i) != DUMMY_MARKER) ?
94 			((((_i) % (_mul)) >= ((_mul) / 2)) ?
95 			((_i) + ((_mul) - 1)) / (_mul) : (_i) / (_mul)) :
96 				DUMMY_MARKER);
97 }
98 
99 #define RXDESC_GET_DATA_LEN(rx_desc) \
100 	(txrx_pdev->htt_pdev->ar_rx_ops->msdu_desc_msdu_length(rx_desc))
101 #define ASSEMBLE_HW_RATECODE(_rate, _nss, _pream)     \
102 	(((_pream) << 6) | ((_nss) << 4) | (_rate))
103 #define GET_HW_RATECODE_PREAM(_rcode)     (((_rcode) >> 6) & 0x3)
104 #define GET_HW_RATECODE_NSS(_rcode)       (((_rcode) >> 4) & 0x3)
105 #define GET_HW_RATECODE_RATE(_rcode)      (((_rcode) >> 0) & 0xF)
106 
107 #define VHT_INVALID_MCS    (0xFF)  /* Certain MCSs are not valid in VHT mode */
108 #define VHT_INVALID_BCC_RATE  0
109 #define NUM_HT_SPATIAL_STREAM 4
110 
111 #define NUM_HT_RIX_PER_BW (NUM_HT_MCS * NUM_HT_SPATIAL_STREAM)
112 #define NUM_VHT_RIX_PER_BW (NUM_VHT_MCS * NUM_SPATIAL_STREAMS)
113 #define NUM_HE_RIX_PER_BW (NUM_HE_MCS * NUM_SPATIAL_STREAMS)
114 
115 #define NUM_VHT_RIX_FOR_160MHZ (NUM_VHT_MCS * \
116 		MAX_SPATIAL_STREAMS_SUPPORTED_AT_160MHZ)
117 #define NUM_HE_RIX_FOR_160MHZ (NUM_HE_MCS * \
118 		MAX_SPATIAL_STREAMS_SUPPORTED_AT_160MHZ)
119 
120 #define CCK_RATE_TABLE_INDEX 0
121 #define CCK_RATE_TABLE_END_INDEX 3
122 #define CCK_RATE_11M_INDEX 0
123 #define CCK_FALLBACK_MIN_RATE 0x3 /** 1 Mbps */
124 #define CCK_FALLBACK_MAX_RATE 0x2 /** 2 Mbps */
125 
126 #define OFDM_RATE_TABLE_INDEX 4
127 #define OFDMA_RATE_54M_INDEX 8
128 #define OFDMA_RATE_TABLE_END_INDEX 11
129 
130 #define HT_20_RATE_TABLE_INDEX 12
131 #define HT_40_RATE_TABLE_INDEX (HT_20_RATE_TABLE_INDEX + NUM_HT_RIX_PER_BW)
132 
133 #define VHT_20_RATE_TABLE_INDEX (HT_40_RATE_TABLE_INDEX + NUM_HT_RIX_PER_BW)
134 #define VHT_40_RATE_TABLE_INDEX (VHT_20_RATE_TABLE_INDEX + NUM_VHT_RIX_PER_BW)
135 #define VHT_80_RATE_TABLE_INDEX (VHT_40_RATE_TABLE_INDEX + NUM_VHT_RIX_PER_BW)
136 
137 #define VHT_160_RATE_TABLE_INDEX (VHT_80_RATE_TABLE_INDEX + NUM_VHT_RIX_PER_BW)
138 #define VHT_LAST_RIX_PLUS_ONE (VHT_160_RATE_TABLE_INDEX + \
139 		NUM_VHT_RIX_FOR_160MHZ)
140 
141 #define HE_20_RATE_TABLE_INDEX VHT_LAST_RIX_PLUS_ONE
142 #define HE_40_RATE_TABLE_INDEX (HE_20_RATE_TABLE_INDEX + NUM_HE_RIX_PER_BW)
143 #define HE_80_RATE_TABLE_INDEX (HE_40_RATE_TABLE_INDEX + NUM_HE_RIX_PER_BW)
144 
145 #define HE_160_RATE_TABLE_INDEX (HE_80_RATE_TABLE_INDEX + NUM_HE_RIX_PER_BW)
146 #define HE_LAST_RIX_PLUS_ONE (HE_160_RATE_TABLE_INDEX + NUM_HE_RIX_FOR_160MHZ)
147 
148 #ifdef WLAN_FEATURE_11BE
149 #define NUM_EHT_SPATIAL_STREAM 4
150 #define NUM_EHT_RIX_PER_BW (NUM_EHT_MCS * NUM_EHT_SPATIAL_STREAM)
151 
152 #define EHT_20_RATE_TABLE_INDEX HE_LAST_RIX_PLUS_ONE
153 #define EHT_40_RATE_TABLE_INDEX (EHT_20_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
154 #define EHT_60_RATE_TABLE_INDEX (EHT_40_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
155 #define EHT_80_RATE_TABLE_INDEX (EHT_60_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
156 #define EHT_120_RATE_TABLE_INDEX (EHT_80_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
157 #define EHT_140_RATE_TABLE_INDEX (EHT_120_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
158 #define EHT_160_RATE_TABLE_INDEX (EHT_140_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
159 #define EHT_200_RATE_TABLE_INDEX (EHT_160_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
160 #define EHT_240_RATE_TABLE_INDEX (EHT_200_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
161 #define EHT_280_RATE_TABLE_INDEX (EHT_240_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
162 #define EHT_320_RATE_TABLE_INDEX (EHT_280_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
163 #define EHT_LAST_RIX_PLUS_ONE (EHT_320_RATE_TABLE_INDEX + NUM_EHT_RIX_PER_BW)
164 #endif
165 
166 #ifdef WLAN_FEATURE_11BE
167 #define DP_RATE_TABLE_SIZE EHT_LAST_RIX_PLUS_ONE
168 #else
169 #define DP_RATE_TABLE_SIZE HE_LAST_RIX_PLUS_ONE
170 #endif
171 
172 #define INVALID_RATE_ERR -1
173 #define NUM_LEGACY_MCS 1
174 
175 /*
176  * The order of the rate types are jumbled below since the current code
177  * implementation is mapped in such way already.
178  *
179  * @DP_HT_RATE: HT Ratetype
180  * @DP_VHT_RATE: VHT Ratetype
181  * @DP_11B_CCK_RATE: 11B CCK Ratetype
182  * @DP_11A_OFDM_RATE: 11A OFDM Ratetype
183  * @DP_11G_CCK_OFDM_RATE: 11G CCK + OFDM Ratetype
184  * @DP_HE_RATE: HE Ratetype
185  */
186 enum DP_CMN_RATE_TYPE {
187 	DP_HT_RATE = 2,
188 	DP_VHT_RATE,
189 	DP_11B_CCK_RATE,
190 	DP_11A_OFDM_RATE,
191 	DP_11G_CCK_OFDM_RATE,
192 	DP_HE_RATE
193 };
194 
195 #define DP_RATEKBPS_SGI(i) (dp_11abgnratetable.info[i].ratekbpssgi)
196 #define DP_RATEKBPS(i) (dp_11abgnratetable.info[i].ratekbps)
197 #define RATE_ROUNDOUT(rate) (((rate) / 1000) * 1000)
198 
199 /* The following would span more than one octet
200  * when 160MHz BW defined for VHT
201  * Also it's important to maintain the ordering of
202  * this enum else it would break other rate adaptation functions.
203  */
204 enum DP_CMN_MODULATION_TYPE {
205 	   DP_CMN_MOD_IEEE80211_T_DS,   /* direct sequence spread spectrum */
206 	   DP_CMN_MOD_IEEE80211_T_OFDM, /* frequency division multiplexing */
207 	   DP_CMN_MOD_IEEE80211_T_HT_20,
208 	   DP_CMN_MOD_IEEE80211_T_HT_40,
209 	   DP_CMN_MOD_IEEE80211_T_VHT_20,
210 	   DP_CMN_MOD_IEEE80211_T_VHT_40,
211 	   DP_CMN_MOD_IEEE80211_T_VHT_80,
212 	   DP_CMN_MOD_IEEE80211_T_VHT_160,
213 	   DP_CMN_MOD_IEEE80211_T_HE_20, /* 11AX support enabled */
214 	   DP_CMN_MOD_IEEE80211_T_HE_40,
215 	   DP_CMN_MOD_IEEE80211_T_HE_80,
216 	   DP_CMN_MOD_IEEE80211_T_HE_160,
217 #ifdef WLAN_FEATURE_11BE
218 	   DP_CMN_MOD_IEEE80211_T_EHT_20,
219 	   DP_CMN_MOD_IEEE80211_T_EHT_40,
220 	   DP_CMN_MOD_IEEE80211_T_EHT_60,
221 	   DP_CMN_MOD_IEEE80211_T_EHT_80,
222 	   DP_CMN_MOD_IEEE80211_T_EHT_120,
223 	   DP_CMN_MOD_IEEE80211_T_EHT_140,
224 	   DP_CMN_MOD_IEEE80211_T_EHT_160,
225 	   DP_CMN_MOD_IEEE80211_T_EHT_200,
226 	   DP_CMN_MOD_IEEE80211_T_EHT_240,
227 	   DP_CMN_MOD_IEEE80211_T_EHT_280,
228 	   DP_CMN_MOD_IEEE80211_T_EHT_320,
229 #endif
230 	   DP_CMN_MOD_IEEE80211_T_MAX_PHY
231 };
232 
233 /* more common nomenclature */
234 #define DP_CMN_MOD_IEEE80211_T_CCK DP_CMN_MOD_IEEE80211_T_DS
235 
236 enum HW_RATECODE_PREAM_TYPE {
237 	HW_RATECODE_PREAM_OFDM,
238 	HW_RATECODE_PREAM_CCK,
239 	HW_RATECODE_PREAM_HT,
240 	HW_RATECODE_PREAM_VHT,
241 	HW_RATECODE_PREAM_HE,
242 #ifdef WLAN_FEATURE_11BE
243 	HW_RATECODE_PREAM_EHT,
244 #endif
245 };
246 
247 #ifdef WLAN_FEATURE_11BE
248 enum BW_TYPES_FP {
249 	BW_20MHZ_F = 0,
250 	BW_40MHZ_F,
251 	BW_60MHZ_P,
252 	BW_80MHZ_F,
253 	BW_120MHZ_P,
254 	BW_140MHZ_P,
255 	BW_160MHZ_F,
256 	BW_200MHZ_P,
257 	BW_240MHZ_P,
258 	BW_280MHZ_P,
259 	BW_320MHZ_F,
260 	BW_FP_CNT,
261 	BW_FP_LAST = BW_320MHZ_F,
262 };
263 #endif
264 
265 enum DP_CMN_MODULATION_TYPE dp_getmodulation(uint16_t pream_type,
266 					     uint8_t width,
267 					     uint8_t punc_mode);
268 
269 uint32_t
270 dp_getrateindex(uint32_t gi, uint16_t mcs, uint8_t nss, uint8_t preamble,
271 		uint8_t bw, uint8_t punc_bw, uint32_t *rix, uint16_t *ratecode);
272 
273 int dp_rate_idx_to_kbps(uint8_t rate_idx, uint8_t gintval);
274 
275 #if ALL_POSSIBLE_RATES_SUPPORTED
276 int dp_get_supported_rates(int mode, int shortgi, int **rates);
277 int dp_get_kbps_to_mcs(int kbps_rate, int shortgi, int htflag);
278 #else
279 int dp_get_supported_rates(int mode, int shortgi, int nss,
280 			   int ch_width, int **rates);
281 int dp_get_kbps_to_mcs(int kbps_rate, int shortgi, int htflag,
282 		       int nss, int ch_width);
283 #endif
284 
285 #endif /*_DP_RATES_H_*/
286