xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723bs/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 
20 /* slot time for 11g */
21 #define SHORT_SLOT_TIME					9
22 #define NON_SHORT_SLOT_TIME				20
23 
24 #define CENTER_CH_2G_40M_NUM	9
25 #define CENTER_CH_2G_NUM		14
26 #define CENTER_CH_5G_20M_NUM	28	/* 20M center channels */
27 #define CENTER_CH_5G_40M_NUM	14	/* 40M center channels */
28 #define CENTER_CH_5G_80M_NUM	7	/* 80M center channels */
29 #define CENTER_CH_5G_160M_NUM	3	/* 160M center channels */
30 #define CENTER_CH_5G_ALL_NUM	(CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM + CENTER_CH_5G_80M_NUM)
31 
32 #define	MAX_CHANNEL_NUM_2G	CENTER_CH_2G_NUM
33 #define	MAX_CHANNEL_NUM_5G	CENTER_CH_5G_20M_NUM
34 #define	MAX_CHANNEL_NUM		(MAX_CHANNEL_NUM_2G + MAX_CHANNEL_NUM_5G)
35 
36 extern u8 center_ch_2g[CENTER_CH_2G_NUM];
37 extern u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM];
38 
39 u8 center_chs_2g_num(u8 bw);
40 u8 center_chs_2g(u8 bw, u8 id);
41 
42 extern u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM];
43 extern u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM];
44 extern u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM];
45 extern u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM];
46 extern u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM];
47 
48 u8 center_chs_5g_num(u8 bw);
49 u8 center_chs_5g(u8 bw, u8 id);
50 
51 u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset);
52 
53 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num);
54 
55 u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group);
56 
57 typedef enum _CAPABILITY {
58 	cESS			= 0x0001,
59 	cIBSS			= 0x0002,
60 	cPollable		= 0x0004,
61 	cPollReq			= 0x0008,
62 	cPrivacy		= 0x0010,
63 	cShortPreamble	= 0x0020,
64 	cPBCC			= 0x0040,
65 	cChannelAgility	= 0x0080,
66 	cSpectrumMgnt	= 0x0100,
67 	cQos			= 0x0200,	/* For HCCA, use with CF-Pollable and CF-PollReq */
68 	cShortSlotTime	= 0x0400,
69 	cAPSD			= 0x0800,
70 	cRM				= 0x1000,	/* RRM (Radio Request Measurement) */
71 	cDSSS_OFDM	= 0x2000,
72 	cDelayedBA		= 0x4000,
73 	cImmediateBA	= 0x8000,
74 } CAPABILITY, *PCAPABILITY;
75 
76 enum	_REG_PREAMBLE_MODE {
77 	PREAMBLE_LONG	= 1,
78 	PREAMBLE_AUTO	= 2,
79 	PREAMBLE_SHORT	= 3,
80 };
81 
82 #define rf_path_char(path) (((path) >= RF_PATH_MAX) ? 'X' : 'A' + (path))
83 
84 /* Bandwidth Offset */
85 #define HAL_PRIME_CHNL_OFFSET_DONT_CARE	0
86 #define HAL_PRIME_CHNL_OFFSET_LOWER	1
87 #define HAL_PRIME_CHNL_OFFSET_UPPER	2
88 
89 typedef enum _BAND_TYPE {
90 	BAND_ON_2_4G = 0,
91 	BAND_ON_5G = 1,
92 	BAND_ON_BOTH = 2,
93 	BAND_MAX = 3,
94 } BAND_TYPE, *PBAND_TYPE;
95 
96 extern const char *const _band_str[];
97 #define band_str(band) (((band) >= BAND_MAX) ? _band_str[BAND_MAX] : _band_str[(band)])
98 
99 extern const u8 _band_to_band_cap[];
100 #define band_to_band_cap(band) (((band) >= BAND_MAX) ? _band_to_band_cap[BAND_MAX] : _band_to_band_cap[(band)])
101 
102 
103 extern const char *const _ch_width_str[];
104 #define ch_width_str(bw) (((bw) >= CHANNEL_WIDTH_MAX) ? _ch_width_str[CHANNEL_WIDTH_MAX] : _ch_width_str[(bw)])
105 
106 extern const u8 _ch_width_to_bw_cap[];
107 #define ch_width_to_bw_cap(bw) (((bw) >= CHANNEL_WIDTH_MAX) ? _ch_width_to_bw_cap[CHANNEL_WIDTH_MAX] : _ch_width_to_bw_cap[(bw)])
108 
109 /*
110  * Represent Extention Channel Offset in HT Capabilities
111  * This is available only in 40Mhz mode.
112  *   */
113 typedef enum _EXTCHNL_OFFSET {
114 	EXTCHNL_OFFSET_NO_EXT = 0,
115 	EXTCHNL_OFFSET_UPPER = 1,
116 	EXTCHNL_OFFSET_NO_DEF = 2,
117 	EXTCHNL_OFFSET_LOWER = 3,
118 } EXTCHNL_OFFSET, *PEXTCHNL_OFFSET;
119 
120 typedef enum _VHT_DATA_SC {
121 	VHT_DATA_SC_DONOT_CARE = 0,
122 	VHT_DATA_SC_20_UPPER_OF_80MHZ = 1,
123 	VHT_DATA_SC_20_LOWER_OF_80MHZ = 2,
124 	VHT_DATA_SC_20_UPPERST_OF_80MHZ = 3,
125 	VHT_DATA_SC_20_LOWEST_OF_80MHZ = 4,
126 	VHT_DATA_SC_20_RECV1 = 5,
127 	VHT_DATA_SC_20_RECV2 = 6,
128 	VHT_DATA_SC_20_RECV3 = 7,
129 	VHT_DATA_SC_20_RECV4 = 8,
130 	VHT_DATA_SC_40_UPPER_OF_80MHZ = 9,
131 	VHT_DATA_SC_40_LOWER_OF_80MHZ = 10,
132 } VHT_DATA_SC, *PVHT_DATA_SC_E;
133 
134 typedef enum _PROTECTION_MODE {
135 	PROTECTION_MODE_AUTO = 0,
136 	PROTECTION_MODE_FORCE_ENABLE = 1,
137 	PROTECTION_MODE_FORCE_DISABLE = 2,
138 } PROTECTION_MODE, *PPROTECTION_MODE;
139 
140 #define RF_TYPE_VALID(rf_type) (rf_type < RF_TYPE_MAX)
141 
142 extern const u8 _rf_type_to_rf_tx_cnt[];
143 #define rf_type_to_rf_tx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_tx_cnt[rf_type] : 0)
144 
145 extern const u8 _rf_type_to_rf_rx_cnt[];
146 #define rf_type_to_rf_rx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_rx_cnt[rf_type] : 0)
147 
148 int rtw_ch2freq(int chan);
149 int rtw_freq2ch(int freq);
150 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo);
151 
152 #define RTW_MODULE_RTL8821AE_HMC_M2		BIT0 /* RTL8821AE(HMC + M.2) */
153 #define RTW_MODULE_RTL8821AU			BIT1 /* RTL8821AU */
154 #define RTW_MODULE_RTL8812AENF_NGFF		BIT2 /* RTL8812AENF(8812AE+8761)_NGFF */
155 #define RTW_MODULE_RTL8812AEBT_HMC		BIT3 /* RTL8812AEBT(8812AE+8761)_HMC */
156 #define RTW_MODULE_RTL8188EE_HMC_M2		BIT4 /* RTL8188EE(HMC + M.2) */
157 #define RTW_MODULE_RTL8723BE_HMC_M2		BIT5 /* RTL8723BE(HMC + M.2) */
158 #define RTW_MODULE_RTL8723BS_NGFF1216	BIT6 /* RTL8723BS(NGFF1216) */
159 #define RTW_MODULE_RTL8192EEBT_HMC_M2	BIT7 /* RTL8192EEBT(8192EE+8761AU)_(HMC + M.2) */
160 #define RTW_MODULE_RTL8723DE_NGFF1630	BIT8 /* RTL8723DE(NGFF1630) */
161 #define RTW_MODULE_RTL8822BE			BIT9 /* RTL8822BE */
162 
163 #define IS_ALPHA2_NO_SPECIFIED(_alpha2) ((*((u16 *)(_alpha2))) == 0xFFFF)
164 
165 struct country_chplan {
166 	char alpha2[2];
167 	u8 chplan;
168 #ifdef CONFIG_80211AC_VHT
169 	u8 en_11ac;
170 #endif
171 #if RTW_DEF_MODULE_REGULATORY_CERT
172 	u16 def_module_flags; /* RTW_MODULE_RTLXXX */
173 #endif
174 };
175 
176 #ifdef CONFIG_80211AC_VHT
177 #define COUNTRY_CHPLAN_EN_11AC(_ent) ((_ent)->en_11ac)
178 #else
179 #define COUNTRY_CHPLAN_EN_11AC(_ent) 0
180 #endif
181 
182 #if RTW_DEF_MODULE_REGULATORY_CERT
183 #define COUNTRY_CHPLAN_DEF_MODULE_FALGS(_ent) ((_ent)->def_module_flags)
184 #else
185 #define COUNTRY_CHPLAN_DEF_MODULE_FALGS(_ent) 0
186 #endif
187 
188 const struct country_chplan *rtw_get_chplan_from_country(const char *country_code);
189 
190 struct rf_ctl_t;
191 
192 typedef enum _REGULATION_TXPWR_LMT {
193 	TXPWR_LMT_NONE = 0, /* no limit */
194 	TXPWR_LMT_FCC = 1,
195 	TXPWR_LMT_MKK = 2,
196 	TXPWR_LMT_ETSI = 3,
197 	TXPWR_LMT_IC = 4,
198 	TXPWR_LMT_KCC = 5,
199 	TXPWR_LMT_WW = 6, /* smallest of all available limit, keep last */
200 } REGULATION_TXPWR_LMT;
201 
202 extern const char *const _regd_str[];
203 #define regd_str(regd) (((regd) > TXPWR_LMT_WW) ? _regd_str[TXPWR_LMT_WW] : _regd_str[(regd)])
204 
205 #ifdef CONFIG_TXPWR_LIMIT
206 struct regd_exc_ent {
207 	_list list;
208 	char country[2];
209 	u8 domain;
210 	char regd_name[0];
211 };
212 
213 void dump_regd_exc_list(void *sel, struct rf_ctl_t *rfctl);
214 void rtw_regd_exc_add_with_nlen(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *regd_name, u32 nlen);
215 void rtw_regd_exc_add(struct rf_ctl_t *rfctl, const char *country, u8 domain, const char *regd_name);
216 struct regd_exc_ent *_rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
217 struct regd_exc_ent *rtw_regd_exc_search(struct rf_ctl_t *rfctl, const char *country, u8 domain);
218 void rtw_regd_exc_list_free(struct rf_ctl_t *rfctl);
219 
220 void dump_txpwr_lmt(void *sel, _adapter *adapter);
221 void rtw_txpwr_lmt_add_with_nlen(struct rf_ctl_t *rfctl, const char *regd_name, u32 nlen
222 	, u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
223 void rtw_txpwr_lmt_add(struct rf_ctl_t *rfctl, const char *regd_name
224 	, u8 band, u8 bw, u8 tlrs, u8 ntx_idx, u8 ch_idx, s8 lmt);
225 struct txpwr_lmt_ent *_rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *regd_name);
226 struct txpwr_lmt_ent *rtw_txpwr_lmt_get_by_name(struct rf_ctl_t *rfctl, const char *regd_name);
227 void rtw_txpwr_lmt_list_free(struct rf_ctl_t *rfctl);
228 #endif /* CONFIG_TXPWR_LIMIT */
229 
230 #define BB_GAIN_2G 0
231 #ifdef CONFIG_IEEE80211_BAND_5GHZ
232 #define BB_GAIN_5GLB1 1
233 #define BB_GAIN_5GLB2 2
234 #define BB_GAIN_5GMB1 3
235 #define BB_GAIN_5GMB2 4
236 #define BB_GAIN_5GHB 5
237 #endif
238 
239 #ifdef CONFIG_IEEE80211_BAND_5GHZ
240 #define BB_GAIN_NUM 6
241 #else
242 #define BB_GAIN_NUM 1
243 #endif
244 
245 int rtw_ch_to_bb_gain_sel(int ch);
246 void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset);
247 void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch);
248 
249 u8 rtw_is_5g_band1(u8 ch);
250 u8 rtw_is_5g_band2(u8 ch);
251 u8 rtw_is_5g_band3(u8 ch);
252 u8 rtw_is_5g_band4(u8 ch);
253 
254 u8 rtw_is_dfs_range(u32 hi, u32 lo);
255 u8 rtw_is_dfs_ch(u8 ch);
256 u8 rtw_is_dfs_chbw(u8 ch, u8 bw, u8 offset);
257 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region);
258 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region);
259 
260 #endif /* _RTL8711_RF_H_ */
261