xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8821cs/include/rtw_rf.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #ifndef	__RTW_RF_H_
16 #define __RTW_RF_H_
17 
18 #define NumRates	(13)
19 #define	B_MODE_RATE_NUM	(4)
20 #define	G_MODE_RATE_NUM	(8)
21 #define	G_MODE_BASIC_RATE_NUM	(3)
22 /* slot time for 11g */
23 #define SHORT_SLOT_TIME					9
24 #define NON_SHORT_SLOT_TIME				20
25 
26 #define CENTER_CH_2G_NUM		14
27 #define CENTER_CH_2G_40M_NUM	9
28 
29 #define CENTER_CH_5G_20M_NUM	28	/* 20M center channels */
30 #define CENTER_CH_5G_40M_NUM	14	/* 40M center channels */
31 #define CENTER_CH_5G_80M_NUM	7	/* 80M center channels */
32 #define CENTER_CH_5G_160M_NUM	3	/* 160M center channels */
33 #define CENTER_CH_5G_ALL_NUM	(CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM + CENTER_CH_5G_80M_NUM)
34 
35 #define CENTER_CH_6G_20M_NUM	64	/* 20M center channels */
36 #define CENTER_CH_6G_40M_NUM	32	/* 40M center channels */
37 #define CENTER_CH_6G_80M_NUM	16	/* 80M center channels */
38 #define CENTER_CH_6G_160M_NUM	8	/* 160M center channels */
39 
40 #define	MAX_CHANNEL_NUM_2G		CENTER_CH_2G_NUM
41 #define	MAX_CHANNEL_NUM_5G		CENTER_CH_5G_20M_NUM
42 #define MAX_CHANNEL_NUM_6G		CENTER_CH_6G_20M_NUM
43 #define MAX_CHANNEL_NUM_2G_5G	(MAX_CHANNEL_NUM_2G + MAX_CHANNEL_NUM_5G)
44 
45 #define	MAX_CHANNEL_NUM		( \
46 	MAX_CHANNEL_NUM_2G \
47 	+ (CONFIG_IEEE80211_BAND_5GHZ ? MAX_CHANNEL_NUM_5G : 0) \
48 	+ (CONFIG_IEEE80211_BAND_6GHZ ? MAX_CHANNEL_NUM_6G : 0) \
49 	)
50 
51 extern u8 center_ch_2g[CENTER_CH_2G_NUM];
52 extern u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM];
53 
54 u8 center_chs_2g_num(u8 bw);
55 u8 center_chs_2g(u8 bw, u8 id);
56 
57 extern u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM];
58 extern u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM];
59 extern u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM];
60 extern u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM];
61 extern u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM];
62 
63 u8 center_chs_5g_num(u8 bw);
64 u8 center_chs_5g(u8 bw, u8 id);
65 
66 u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset);
67 u8 rtw_get_scch_by_cch_opch(u8 cch, u8 bw, u8 opch);
68 
69 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num);
70 
71 u8 rtw_get_offset_by_chbw(u8 ch, u8 bw, u8 *r_offset);
72 u8 rtw_get_center_ch(u8 ch, u8 bw, u8 offset);
73 
74 u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group);
75 
76 typedef enum _CAPABILITY {
77 	cESS			= 0x0001,
78 	cIBSS			= 0x0002,
79 	cPollable		= 0x0004,
80 	cPollReq			= 0x0008,
81 	cPrivacy		= 0x0010,
82 	cShortPreamble	= 0x0020,
83 	cPBCC			= 0x0040,
84 	cChannelAgility	= 0x0080,
85 	cSpectrumMgnt	= 0x0100,
86 	cQos			= 0x0200,	/* For HCCA, use with CF-Pollable and CF-PollReq */
87 	cShortSlotTime	= 0x0400,
88 	cAPSD			= 0x0800,
89 	cRM				= 0x1000,	/* RRM (Radio Request Measurement) */
90 	cDSSS_OFDM	= 0x2000,
91 	cDelayedBA		= 0x4000,
92 	cImmediateBA	= 0x8000,
93 } CAPABILITY, *PCAPABILITY;
94 
95 enum	_REG_PREAMBLE_MODE {
96 	PREAMBLE_LONG	= 1,
97 	PREAMBLE_AUTO	= 2,
98 	PREAMBLE_SHORT	= 3,
99 };
100 
101 #define rf_path_char(path) (((path) >= RF_PATH_MAX) ? 'X' : 'A' + (path))
102 
103 /* Bandwidth Offset */
104 #define HAL_PRIME_CHNL_OFFSET_DONT_CARE	0
105 #define HAL_PRIME_CHNL_OFFSET_LOWER	1
106 #define HAL_PRIME_CHNL_OFFSET_UPPER	2
107 
108 typedef enum _BAND_TYPE {
109 	BAND_ON_2_4G = 0,
110 	BAND_ON_5G = 1,
111 #if CONFIG_IEEE80211_BAND_6GHZ
112 	BAND_ON_6G = 2,
113 #endif
114 	BAND_MAX,
115 } BAND_TYPE, *PBAND_TYPE;
116 
117 #ifdef CONFIG_NARROWBAND_SUPPORTING
118 enum nb_config {
119 	RTW_NB_CONFIG_NONE		= 0,
120 	RTW_NB_CONFIG_WIDTH_5	= 5,
121 	RTW_NB_CONFIG_WIDTH_10	= 6,
122 };
123 #endif
124 
125 extern const char *const _band_str[];
126 #define band_str(band) (((band) >= BAND_MAX) ? _band_str[BAND_MAX] : _band_str[(band)])
127 
128 extern const u8 _band_to_band_cap[];
129 #define band_to_band_cap(band) (((band) >= BAND_MAX) ? _band_to_band_cap[BAND_MAX] : _band_to_band_cap[(band)])
130 
131 
132 extern const char *const _ch_width_str[];
133 #define ch_width_str(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_str[(bw)] : "CHANNEL_WIDTH_MAX")
134 
135 extern const u8 _ch_width_to_bw_cap[];
136 #define ch_width_to_bw_cap(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_to_bw_cap[(bw)] : 0)
137 
138 enum opc_bw {
139 	OPC_BW20		= 0,
140 	OPC_BW40PLUS	= 1,
141 	OPC_BW40MINUS	= 2,
142 	OPC_BW80		= 3,
143 	OPC_BW160		= 4,
144 	OPC_BW80P80		= 5,
145 	OPC_BW_NUM,
146 };
147 
148 extern const char *const _opc_bw_str[OPC_BW_NUM];
149 #define opc_bw_str(bw) (((bw) < OPC_BW_NUM) ? _opc_bw_str[(bw)] : "N/A")
150 
151 extern const u8 _opc_bw_to_ch_width[OPC_BW_NUM];
152 #define opc_bw_to_ch_width(bw) (((bw) < OPC_BW_NUM) ? _opc_bw_to_ch_width[(bw)] : CHANNEL_WIDTH_MAX)
153 
154 /* global op class APIs */
155 bool is_valid_global_op_class_id(u8 gid);
156 s16 get_sub_op_class(u8 gid, u8 ch);
157 void dump_global_op_class(void *sel);
158 u8 rtw_get_op_class_by_chbw(u8 ch, u8 bw, u8 offset);
159 u8 rtw_get_bw_offset_by_op_class_ch(u8 gid, u8 ch, u8 *bw, u8 *offset);
160 
161 struct op_ch_t {
162 	u8 ch;
163 	u8 static_non_op:1; /* not in channel list */
164 	u8 no_ir:1;
165 	s16 max_txpwr; /* mBm */
166 };
167 
168 struct op_class_pref_t {
169 	u8 class_id;
170 	BAND_TYPE band;
171 	enum opc_bw bw;
172 	u8 ch_num; /* number of chs */
173 	u8 op_ch_num; /* channel number which is not static non operable */
174 	u8 ir_ch_num; /* channel number which can init radiation */
175 	struct op_ch_t chs[];
176 };
177 
178 int op_class_pref_init(_adapter *adapter);
179 void op_class_pref_deinit(_adapter *adapter);
180 
181 #define REG_BEACON_HINT		0
182 #define REG_TXPWR_CHANGE	1
183 #define REG_CHANGE			2
184 
185 void op_class_pref_apply_regulatory(_adapter *adapter, u8 reason);
186 
187 struct rf_ctl_t;
188 void dump_cap_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool detail);
189 void dump_reg_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool detail);
190 void dump_cur_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool detail);
191 
192 /*
193  * Represent Extention Channel Offset in HT Capabilities
194  * This is available only in 40Mhz mode.
195  *   */
196 typedef enum _EXTCHNL_OFFSET {
197 	EXTCHNL_OFFSET_NO_EXT = 0,
198 	EXTCHNL_OFFSET_UPPER = 1,
199 	EXTCHNL_OFFSET_NO_DEF = 2,
200 	EXTCHNL_OFFSET_LOWER = 3,
201 } EXTCHNL_OFFSET, *PEXTCHNL_OFFSET;
202 
203 typedef enum _VHT_DATA_SC {
204 	VHT_DATA_SC_DONOT_CARE = 0,
205 	VHT_DATA_SC_20_UPPER_OF_80MHZ = 1,
206 	VHT_DATA_SC_20_LOWER_OF_80MHZ = 2,
207 	VHT_DATA_SC_20_UPPERST_OF_80MHZ = 3,
208 	VHT_DATA_SC_20_LOWEST_OF_80MHZ = 4,
209 	VHT_DATA_SC_20_RECV1 = 5,
210 	VHT_DATA_SC_20_RECV2 = 6,
211 	VHT_DATA_SC_20_RECV3 = 7,
212 	VHT_DATA_SC_20_RECV4 = 8,
213 	VHT_DATA_SC_40_UPPER_OF_80MHZ = 9,
214 	VHT_DATA_SC_40_LOWER_OF_80MHZ = 10,
215 } VHT_DATA_SC, *PVHT_DATA_SC_E;
216 
217 typedef enum _PROTECTION_MODE {
218 	PROTECTION_MODE_AUTO = 0,
219 	PROTECTION_MODE_FORCE_ENABLE = 1,
220 	PROTECTION_MODE_FORCE_DISABLE = 2,
221 } PROTECTION_MODE, *PPROTECTION_MODE;
222 
223 #define RF_TYPE_VALID(rf_type) (rf_type < RF_TYPE_MAX)
224 
225 extern const u8 _rf_type_to_rf_tx_cnt[];
226 #define rf_type_to_rf_tx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_tx_cnt[rf_type] : 0)
227 
228 extern const u8 _rf_type_to_rf_rx_cnt[];
229 #define rf_type_to_rf_rx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_rx_cnt[rf_type] : 0)
230 
231 extern const char *const _rf_type_to_rfpath_str[];
232 #define rf_type_to_rfpath_str(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rfpath_str[rf_type] : "UNKNOWN")
233 
234 void rf_type_to_default_trx_bmp(enum rf_type rf, enum bb_path *tx, enum bb_path *rx);
235 
236 enum rf_type trx_num_to_rf_type(u8 tx_num, u8 rx_num);
237 enum rf_type trx_bmp_to_rf_type(u8 tx_bmp, u8 rx_bmp);
238 bool rf_type_is_a_in_b(enum rf_type a, enum rf_type b);
239 u8 rtw_restrict_trx_path_bmp_by_trx_num_lmt(u8 trx_path_bmp, u8 tx_num_lmt, u8 rx_num_lmt, u8 *tx_num, u8 *rx_num);
240 u8 rtw_restrict_trx_path_bmp_by_rftype(u8 trx_path_bmp, enum rf_type type, u8 *tx_num, u8 *rx_num);
241 void tx_path_nss_set_default(enum bb_path txpath_nss[], u8 txpath_num_nss[], u8 txpath);
242 void tx_path_nss_set_full_tx(enum bb_path txpath_nss[], u8 txpath_num_nss[], u8 txpath);
243 
244 #if CONFIG_IEEE80211_BAND_6GHZ
245 int rtw_6gch2freq(int chan);
246 #endif
247 
248 int rtw_ch2freq(int chan);
249 int rtw_ch2freq_by_band(BAND_TYPE band, int ch);
250 int rtw_freq2ch(int freq);
251 BAND_TYPE rtw_freq2band(int freq);
252 bool rtw_freq_consecutive(int a, int b);
253 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo);
254 
255 struct rf_ctl_t;
256 
257 void txpwr_idx_get_dbm_str(s8 idx, u8 txgi_max, u8 txgi_pdbm, SIZE_T cwidth, char dbm_str[], u8 dbm_str_len);
258 
259 #define MBM_PDBM 100
260 #define UNSPECIFIED_MBM 32767 /* maximum of s16 */
261 
262 void txpwr_mbm_get_dbm_str(s16 mbm, SIZE_T cwidth, char dbm_str[], u8 dbm_str_len);
263 s16 mb_of_ntx(u8 ntx);
264 
265 #if CONFIG_TXPWR_LIMIT
266 struct regd_exc_ent {
267 	_list list;
268 	char country[2];
269 	u8 domain;
270 	char lmt_name[0];
271 };
272 
273 void dump_regd_exc_list(void *sel, struct rf_ctl_t *rfctl);
274 void rtw_regd_exc_add_with_nlen(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *lmt_name, u32 nlen);
275 void rtw_regd_exc_add(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *lmt_name);
276 struct regd_exc_ent *_rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
277 struct regd_exc_ent *rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
278 void rtw_regd_exc_list_free(struct rf_ctl_t *rfctl);
279 
280 void dump_txpwr_lmt(void *sel, _adapter *adapter);
281 void rtw_txpwr_lmt_add_with_nlen(struct rf_ctl_t *rfctl, const char *lmt_name, u32 nlen
282 	, u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
283 void rtw_txpwr_lmt_add(struct rf_ctl_t *rfctl, const char *lmt_name
284 	, u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
285 struct txpwr_lmt_ent *_rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *lmt_name);
286 struct txpwr_lmt_ent *rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *lmt_name);
287 void rtw_txpwr_lmt_list_free(struct rf_ctl_t *rfctl);
288 #endif /* CONFIG_TXPWR_LIMIT */
289 
290 #define BB_GAIN_2G 0
291 #if CONFIG_IEEE80211_BAND_5GHZ
292 #define BB_GAIN_5GLB1 1
293 #define BB_GAIN_5GLB2 2
294 #define BB_GAIN_5GMB1 3
295 #define BB_GAIN_5GMB2 4
296 #define BB_GAIN_5GHB 5
297 #endif
298 
299 #if CONFIG_IEEE80211_BAND_5GHZ
300 #define BB_GAIN_NUM 6
301 #else
302 #define BB_GAIN_NUM 1
303 #endif
304 
305 int rtw_ch_to_bb_gain_sel(int ch);
306 void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset);
307 void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch);
308 
309 /* only check channel ranges */
310 #define rtw_is_2g_ch(ch) (ch >= 1 && ch <= 14)
311 #define rtw_is_5g_ch(ch) ((ch) >= 36 && (ch) <= 177)
312 #define rtw_is_same_band(a, b) \
313 	((rtw_is_2g_ch(a) && rtw_is_2g_ch(b)) \
314 	|| (rtw_is_5g_ch(a) && rtw_is_5g_ch(b)))
315 
316 #define rtw_is_5g_band1(ch) ((ch) >= 36 && (ch) <= 48)
317 #define rtw_is_5g_band2(ch) ((ch) >= 52 && (ch) <= 64)
318 #define rtw_is_5g_band3(ch) ((ch) >= 100 && (ch) <= 144)
319 #define rtw_is_5g_band4(ch) ((ch) >= 149 && (ch) <= 177)
320 #define rtw_is_same_5g_band(a, b) \
321 	((rtw_is_5g_band1(a) && rtw_is_5g_band1(b)) \
322 	|| (rtw_is_5g_band2(a) && rtw_is_5g_band2(b)) \
323 	|| (rtw_is_5g_band3(a) && rtw_is_5g_band3(b)) \
324 	|| (rtw_is_5g_band4(a) && rtw_is_5g_band4(b)))
325 
326 #define rtw_is_6g_band1(ch) ((ch) >= 1 && (ch) <= 93)
327 #define rtw_is_6g_band2(ch) ((ch) >= 97 && (ch) <= 117)
328 #define rtw_is_6g_band3(ch) ((ch) >= 121 && (ch) <= 189)
329 #define rtw_is_6g_band4(ch) ((ch) >= 193 && (ch) <= 237)
330 
331 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region);
332 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region);
333 
334 #endif /* _RTL8711_RF_H_ */
335