xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8188fu/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_40M_NUM	9
27 #define CENTER_CH_2G_NUM		14
28 #define CENTER_CH_5G_20M_NUM	28	/* 20M center channels */
29 #define CENTER_CH_5G_40M_NUM	14	/* 40M center channels */
30 #define CENTER_CH_5G_80M_NUM	7	/* 80M center channels */
31 #define CENTER_CH_5G_160M_NUM	3	/* 160M center channels */
32 #define CENTER_CH_5G_ALL_NUM	(CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM + CENTER_CH_5G_80M_NUM)
33 
34 #define	MAX_CHANNEL_NUM_2G	CENTER_CH_2G_NUM
35 #define	MAX_CHANNEL_NUM_5G	CENTER_CH_5G_20M_NUM
36 #define	MAX_CHANNEL_NUM		(MAX_CHANNEL_NUM_2G + MAX_CHANNEL_NUM_5G)
37 
38 extern u8 center_ch_2g[CENTER_CH_2G_NUM];
39 extern u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM];
40 
41 u8 center_chs_2g_num(u8 bw);
42 u8 center_chs_2g(u8 bw, u8 id);
43 
44 extern u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM];
45 extern u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM];
46 extern u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM];
47 extern u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM];
48 extern u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM];
49 
50 u8 center_chs_5g_num(u8 bw);
51 u8 center_chs_5g(u8 bw, u8 id);
52 
53 u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset);
54 u8 rtw_get_scch_by_cch_opch(u8 cch, u8 bw, u8 opch);
55 
56 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num);
57 
58 u8 rtw_get_offset_by_chbw(u8 ch, u8 bw, u8 *r_offset);
59 u8 rtw_get_center_ch(u8 ch, u8 bw, u8 offset);
60 
61 u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group);
62 
63 typedef enum _CAPABILITY {
64 	cESS			= 0x0001,
65 	cIBSS			= 0x0002,
66 	cPollable		= 0x0004,
67 	cPollReq			= 0x0008,
68 	cPrivacy		= 0x0010,
69 	cShortPreamble	= 0x0020,
70 	cPBCC			= 0x0040,
71 	cChannelAgility	= 0x0080,
72 	cSpectrumMgnt	= 0x0100,
73 	cQos			= 0x0200,	/* For HCCA, use with CF-Pollable and CF-PollReq */
74 	cShortSlotTime	= 0x0400,
75 	cAPSD			= 0x0800,
76 	cRM				= 0x1000,	/* RRM (Radio Request Measurement) */
77 	cDSSS_OFDM	= 0x2000,
78 	cDelayedBA		= 0x4000,
79 	cImmediateBA	= 0x8000,
80 } CAPABILITY, *PCAPABILITY;
81 
82 enum	_REG_PREAMBLE_MODE {
83 	PREAMBLE_LONG	= 1,
84 	PREAMBLE_AUTO	= 2,
85 	PREAMBLE_SHORT	= 3,
86 };
87 
88 #define rf_path_char(path) (((path) >= RF_PATH_MAX) ? 'X' : 'A' + (path))
89 
90 /* Bandwidth Offset */
91 #define HAL_PRIME_CHNL_OFFSET_DONT_CARE	0
92 #define HAL_PRIME_CHNL_OFFSET_LOWER	1
93 #define HAL_PRIME_CHNL_OFFSET_UPPER	2
94 
95 typedef enum _BAND_TYPE {
96 	BAND_ON_2_4G = 0,
97 	BAND_ON_5G = 1,
98 	BAND_MAX,
99 } BAND_TYPE, *PBAND_TYPE;
100 
101 #ifdef CONFIG_NARROWBAND_SUPPORTING
102 enum nb_config {
103 	RTW_NB_CONFIG_NONE		= 0,
104 	RTW_NB_CONFIG_WIDTH_5	= 5,
105 	RTW_NB_CONFIG_WIDTH_10	= 6,
106 };
107 #endif
108 
109 extern const char *const _band_str[];
110 #define band_str(band) (((band) >= BAND_MAX) ? _band_str[BAND_MAX] : _band_str[(band)])
111 
112 extern const u8 _band_to_band_cap[];
113 #define band_to_band_cap(band) (((band) >= BAND_MAX) ? _band_to_band_cap[BAND_MAX] : _band_to_band_cap[(band)])
114 
115 
116 extern const char *const _ch_width_str[];
117 #define ch_width_str(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_str[(bw)] : "CHANNEL_WIDTH_MAX")
118 
119 extern const u8 _ch_width_to_bw_cap[];
120 #define ch_width_to_bw_cap(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_to_bw_cap[(bw)] : 0)
121 
122 enum opc_bw {
123 	OPC_BW20		= 0,
124 	OPC_BW40PLUS	= 1,
125 	OPC_BW40MINUS	= 2,
126 	OPC_BW80		= 3,
127 	OPC_BW160		= 4,
128 	OPC_BW80P80		= 5,
129 	OPC_BW_NUM,
130 };
131 
132 extern const char *const _opc_bw_str[OPC_BW_NUM];
133 #define opc_bw_str(bw) (((bw) < OPC_BW_NUM) ? _opc_bw_str[(bw)] : "N/A")
134 
135 extern const u8 _opc_bw_to_ch_width[OPC_BW_NUM];
136 #define opc_bw_to_ch_width(bw) (((bw) < OPC_BW_NUM) ? _opc_bw_to_ch_width[(bw)] : CHANNEL_WIDTH_MAX)
137 
138 struct op_class_map {
139 	u8 op_class;
140 	BAND_TYPE band;
141 	enum opc_bw bw;
142 	u32 ch_bmp;
143 };
144 
145 #define RTW_GLOBAL_OP_CLASS_NUM 19
146 
147 void dump_global_op_class(void *sel);
148 
149 u8 rtw_get_op_class_by_chbw(u8 ch, u8 bw, u8 offset);
150 u8 rtw_get_bw_offset_by_op_class_ch(u8 op_class, u8 ch, u8 *bw, u8 *offset);
151 
152 struct _RT_CHANNEL_INFO;
153 u8 init_op_class_ch_bmp(_adapter *adapter, struct _RT_CHANNEL_INFO *chset, u32 op_class_ch_bmp[]);
154 struct rf_ctl_t;
155 void dump_cap_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool negtive);
156 void dump_cur_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool negtive);
157 
158 /*
159  * Represent Extention Channel Offset in HT Capabilities
160  * This is available only in 40Mhz mode.
161  *   */
162 typedef enum _EXTCHNL_OFFSET {
163 	EXTCHNL_OFFSET_NO_EXT = 0,
164 	EXTCHNL_OFFSET_UPPER = 1,
165 	EXTCHNL_OFFSET_NO_DEF = 2,
166 	EXTCHNL_OFFSET_LOWER = 3,
167 } EXTCHNL_OFFSET, *PEXTCHNL_OFFSET;
168 
169 typedef enum _VHT_DATA_SC {
170 	VHT_DATA_SC_DONOT_CARE = 0,
171 	VHT_DATA_SC_20_UPPER_OF_80MHZ = 1,
172 	VHT_DATA_SC_20_LOWER_OF_80MHZ = 2,
173 	VHT_DATA_SC_20_UPPERST_OF_80MHZ = 3,
174 	VHT_DATA_SC_20_LOWEST_OF_80MHZ = 4,
175 	VHT_DATA_SC_20_RECV1 = 5,
176 	VHT_DATA_SC_20_RECV2 = 6,
177 	VHT_DATA_SC_20_RECV3 = 7,
178 	VHT_DATA_SC_20_RECV4 = 8,
179 	VHT_DATA_SC_40_UPPER_OF_80MHZ = 9,
180 	VHT_DATA_SC_40_LOWER_OF_80MHZ = 10,
181 } VHT_DATA_SC, *PVHT_DATA_SC_E;
182 
183 typedef enum _PROTECTION_MODE {
184 	PROTECTION_MODE_AUTO = 0,
185 	PROTECTION_MODE_FORCE_ENABLE = 1,
186 	PROTECTION_MODE_FORCE_DISABLE = 2,
187 } PROTECTION_MODE, *PPROTECTION_MODE;
188 
189 #define RF_TYPE_VALID(rf_type) (rf_type < RF_TYPE_MAX)
190 
191 extern const u8 _rf_type_to_rf_tx_cnt[];
192 #define rf_type_to_rf_tx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_tx_cnt[rf_type] : 0)
193 
194 extern const u8 _rf_type_to_rf_rx_cnt[];
195 #define rf_type_to_rf_rx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_rx_cnt[rf_type] : 0)
196 
197 extern const char *const _rf_type_to_rfpath_str[];
198 #define rf_type_to_rfpath_str(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rfpath_str[rf_type] : "UNKNOWN")
199 
200 void rf_type_to_default_trx_bmp(enum rf_type rf, enum bb_path *tx, enum bb_path *rx);
201 
202 enum rf_type trx_num_to_rf_type(u8 tx_num, u8 rx_num);
203 enum rf_type trx_bmp_to_rf_type(u8 tx_bmp, u8 rx_bmp);
204 bool rf_type_is_a_in_b(enum rf_type a, enum rf_type b);
205 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);
206 u8 rtw_restrict_trx_path_bmp_by_rftype(u8 trx_path_bmp, enum rf_type type, u8 *tx_num, u8 *rx_num);
207 void tx_path_nss_set_default(enum bb_path txpath_nss[], u8 txpath_num_nss[], u8 txpath);
208 void tx_path_nss_set_full_tx(enum bb_path txpath_nss[], u8 txpath_num_nss[], u8 txpath);
209 
210 int rtw_ch2freq(int chan);
211 int rtw_freq2ch(int freq);
212 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo);
213 
214 struct rf_ctl_t;
215 
216 typedef enum _REGULATION_TXPWR_LMT {
217 	TXPWR_LMT_NONE = 0, /* no limit */
218 	TXPWR_LMT_FCC = 1,
219 	TXPWR_LMT_MKK = 2,
220 	TXPWR_LMT_ETSI = 3,
221 	TXPWR_LMT_IC = 4,
222 	TXPWR_LMT_KCC = 5,
223 	TXPWR_LMT_ACMA = 6,
224 	TXPWR_LMT_CHILE = 7,
225 	TXPWR_LMT_UKRAINE = 8,
226 	TXPWR_LMT_MEXICO = 9,
227 	TXPWR_LMT_CN = 10,
228 	TXPWR_LMT_WW, /* smallest of all available limit, keep last */
229 } REGULATION_TXPWR_LMT;
230 
231 extern const char *const _regd_str[];
232 #define regd_str(regd) (((regd) > TXPWR_LMT_WW) ? _regd_str[TXPWR_LMT_WW] : _regd_str[(regd)])
233 
234 void txpwr_idx_get_dbm_str(s8 idx, u8 txgi_max, u8 txgi_pdbm, SIZE_T cwidth, char dbm_str[], u8 dbm_str_len);
235 
236 #define MBM_PDBM 100
237 #define UNSPECIFIED_MBM 32767 /* maximum of s16 */
238 
239 void txpwr_mbm_get_dbm_str(s16 mbm, SIZE_T cwidth, char dbm_str[], u8 dbm_str_len);
240 s16 mb_of_ntx(u8 ntx);
241 
242 #if CONFIG_TXPWR_LIMIT
243 struct regd_exc_ent {
244 	_list list;
245 	char country[2];
246 	u8 domain;
247 	char regd_name[0];
248 };
249 
250 void dump_regd_exc_list(void *sel, struct rf_ctl_t *rfctl);
251 void rtw_regd_exc_add_with_nlen(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *regd_name, u32 nlen);
252 void rtw_regd_exc_add(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *regd_name);
253 struct regd_exc_ent *_rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
254 struct regd_exc_ent *rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
255 void rtw_regd_exc_list_free(struct rf_ctl_t *rfctl);
256 
257 void dump_txpwr_lmt(void *sel, _adapter *adapter);
258 void rtw_txpwr_lmt_add_with_nlen(struct rf_ctl_t *rfctl, const char *regd_name, u32 nlen
259 	, u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
260 void rtw_txpwr_lmt_add(struct rf_ctl_t *rfctl, const char *regd_name
261 	, u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
262 struct txpwr_lmt_ent *_rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *regd_name);
263 struct txpwr_lmt_ent *rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *regd_name);
264 void rtw_txpwr_lmt_list_free(struct rf_ctl_t *rfctl);
265 #endif /* CONFIG_TXPWR_LIMIT */
266 
267 #define BB_GAIN_2G 0
268 #if CONFIG_IEEE80211_BAND_5GHZ
269 #define BB_GAIN_5GLB1 1
270 #define BB_GAIN_5GLB2 2
271 #define BB_GAIN_5GMB1 3
272 #define BB_GAIN_5GMB2 4
273 #define BB_GAIN_5GHB 5
274 #endif
275 
276 #if CONFIG_IEEE80211_BAND_5GHZ
277 #define BB_GAIN_NUM 6
278 #else
279 #define BB_GAIN_NUM 1
280 #endif
281 
282 int rtw_ch_to_bb_gain_sel(int ch);
283 void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset);
284 void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch);
285 
286 /* only check channel ranges */
287 #define rtw_is_2g_ch(ch) (ch >= 1 && ch <= 14)
288 #define rtw_is_5g_ch(ch) ((ch) >= 36 && (ch) <= 177)
289 #define rtw_is_same_band(a, b) \
290 	((rtw_is_2g_ch(a) && rtw_is_2g_ch(b)) \
291 	|| (rtw_is_5g_ch(a) && rtw_is_5g_ch(b)))
292 
293 #define rtw_is_5g_band1(ch) ((ch) >= 36 && (ch) <= 48)
294 #define rtw_is_5g_band2(ch) ((ch) >= 52 && (ch) <= 64)
295 #define rtw_is_5g_band3(ch) ((ch) >= 100 && (ch) <= 144)
296 #define rtw_is_5g_band4(ch) ((ch) >= 149 && (ch) <= 177)
297 #define rtw_is_same_5g_band(a, b) \
298 	((rtw_is_5g_band1(a) && rtw_is_5g_band1(b)) \
299 	|| (rtw_is_5g_band2(a) && rtw_is_5g_band2(b)) \
300 	|| (rtw_is_5g_band3(a) && rtw_is_5g_band3(b)) \
301 	|| (rtw_is_5g_band4(a) && rtw_is_5g_band4(b)))
302 
303 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region);
304 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region);
305 
306 #endif /* _RTL8711_RF_H_ */
307