net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / include / rtw_rf.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef __RTW_RF_H_
21 #define __RTW_RF_H_
22
23
24 #define OFDM_PHY                1
25 #define MIXED_PHY               2
26 #define CCK_PHY         3
27
28 #define NumRates        (13)
29
30 /* slot time for 11g */
31 #define SHORT_SLOT_TIME                                 9
32 #define NON_SHORT_SLOT_TIME                             20
33
34 #define RTL8711_RF_MAX_SENS 6
35 #define RTL8711_RF_DEF_SENS 4
36
37 /*
38  * We now define the following channels as the max channels in each channel plan.
39  * 2G, total 14 chnls
40  * {1,2,3,4,5,6,7,8,9,10,11,12,13,14}
41  * 5G, total 25 chnls
42  * {36,40,44,48,52,56,60,64,100,104,108,112,116,120,124,128,132,136,140,144,149,153,157,161,165}
43  */
44 #define MAX_CHANNEL_NUM_2G      14
45 #define MAX_CHANNEL_NUM_5G      25
46 #define MAX_CHANNEL_NUM         (MAX_CHANNEL_NUM_2G + MAX_CHANNEL_NUM_5G)
47
48 #define CENTER_CH_2G_40M_NUM    9
49 #define CENTER_CH_2G_NUM                14
50 #define CENTER_CH_5G_20M_NUM    28      /* 20M center channels */
51 #define CENTER_CH_5G_40M_NUM    14      /* 40M center channels */
52 #define CENTER_CH_5G_80M_NUM    7       /* 80M center channels */
53 #define CENTER_CH_5G_160M_NUM   3       /* 160M center channels */
54 #define CENTER_CH_5G_ALL_NUM    (CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM + CENTER_CH_5G_80M_NUM)
55
56 extern u8 center_ch_2g[CENTER_CH_2G_NUM];
57 extern u8 center_ch_2g_40m[CENTER_CH_2G_40M_NUM];
58
59 u8 center_chs_2g_num(u8 bw);
60 u8 center_chs_2g(u8 bw, u8 id);
61
62 extern u8 center_ch_5g_20m[CENTER_CH_5G_20M_NUM];
63 extern u8 center_ch_5g_40m[CENTER_CH_5G_40M_NUM];
64 extern u8 center_ch_5g_20m_40m[CENTER_CH_5G_20M_NUM + CENTER_CH_5G_40M_NUM];
65 extern u8 center_ch_5g_80m[CENTER_CH_5G_80M_NUM];
66 extern u8 center_ch_5g_all[CENTER_CH_5G_ALL_NUM];
67
68 u8 center_chs_5g_num(u8 bw);
69 u8 center_chs_5g(u8 bw, u8 id);
70
71 u8 rtw_get_scch_by_cch_offset(u8 cch, u8 bw, u8 offset);
72
73 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num);
74
75 u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group);
76
77 /* #define NUM_REGULATORYS      21 */
78 #define NUM_REGULATORYS 1
79
80 /* Country codes */
81 #define USA                                                     0x555320
82 #define EUROPE                                          0x1 /* temp, should be provided later    */
83 #define JAPAN                                           0x2 /* temp, should be provided later    */
84
85 struct  regulatory_class {
86         u32     starting_freq;                                  /* MHz, */
87         u8      channel_set[MAX_CHANNEL_NUM];
88         u8      channel_cck_power[MAX_CHANNEL_NUM];/* dbm */
89         u8      channel_ofdm_power[MAX_CHANNEL_NUM];/* dbm */
90         u8      txpower_limit;                                  /* dbm */
91         u8      channel_spacing;                                /* MHz */
92         u8      modem;
93 };
94
95 typedef enum _CAPABILITY {
96         cESS                    = 0x0001,
97         cIBSS                   = 0x0002,
98         cPollable               = 0x0004,
99         cPollReq                        = 0x0008,
100         cPrivacy                = 0x0010,
101         cShortPreamble  = 0x0020,
102         cPBCC                   = 0x0040,
103         cChannelAgility = 0x0080,
104         cSpectrumMgnt   = 0x0100,
105         cQos                    = 0x0200,       /* For HCCA, use with CF-Pollable and CF-PollReq */
106         cShortSlotTime  = 0x0400,
107         cAPSD                   = 0x0800,
108         cRM                             = 0x1000,       /* RRM (Radio Request Measurement) */
109         cDSSS_OFDM      = 0x2000,
110         cDelayedBA              = 0x4000,
111         cImmediateBA    = 0x8000,
112 } CAPABILITY, *PCAPABILITY;
113
114 enum    _REG_PREAMBLE_MODE {
115         PREAMBLE_LONG   = 1,
116         PREAMBLE_AUTO   = 2,
117         PREAMBLE_SHORT  = 3,
118 };
119
120
121 enum _RTL8712_RF_MIMO_CONFIG_ {
122         RTL8712_RFCONFIG_1T = 0x10,
123         RTL8712_RFCONFIG_2T = 0x20,
124         RTL8712_RFCONFIG_1R = 0x01,
125         RTL8712_RFCONFIG_2R = 0x02,
126         RTL8712_RFCONFIG_1T1R = 0x11,
127         RTL8712_RFCONFIG_1T2R = 0x12,
128         RTL8712_RFCONFIG_TURBO = 0x92,
129         RTL8712_RFCONFIG_2T2R = 0x22
130 };
131
132 typedef enum _RF_PATH {
133         RF_PATH_A = 0,
134         RF_PATH_B = 1,
135         RF_PATH_C = 2,
136         RF_PATH_D = 3,
137 } RF_PATH, *PRF_PATH;
138
139 #define rf_path_char(path) (((path) >= RF_PATH_MAX) ? 'X' : 'A' + (path))
140
141 /* Bandwidth Offset */
142 #define HAL_PRIME_CHNL_OFFSET_DONT_CARE 0
143 #define HAL_PRIME_CHNL_OFFSET_LOWER     1
144 #define HAL_PRIME_CHNL_OFFSET_UPPER     2
145
146 typedef enum _BAND_TYPE {
147         BAND_ON_2_4G = 0,
148         BAND_ON_5G = 1,
149         BAND_ON_BOTH = 2,
150         BAND_MAX = 3,
151 } BAND_TYPE, *PBAND_TYPE;
152
153 extern const char *const _band_str[];
154 #define band_str(band) (((band) >= BAND_MAX) ? _band_str[BAND_MAX] : _band_str[(band)])
155
156 extern const u8 _band_to_band_cap[];
157 #define band_to_band_cap(band) (((band) >= BAND_MAX) ? _band_to_band_cap[BAND_MAX] : _band_to_band_cap[(band)])
158
159 /* Represent Channel Width in HT Capabilities
160  *   */
161 typedef enum _CHANNEL_WIDTH {
162         CHANNEL_WIDTH_20 = 0,
163         CHANNEL_WIDTH_40 = 1,
164         CHANNEL_WIDTH_80 = 2,
165         CHANNEL_WIDTH_160 = 3,
166         CHANNEL_WIDTH_80_80 = 4,
167         CHANNEL_WIDTH_MAX = 5,
168 } CHANNEL_WIDTH, *PCHANNEL_WIDTH;
169
170 extern const char *const _ch_width_str[];
171 #define ch_width_str(bw) (((bw) >= CHANNEL_WIDTH_MAX) ? _ch_width_str[CHANNEL_WIDTH_MAX] : _ch_width_str[(bw)])
172
173 extern const u8 _ch_width_to_bw_cap[];
174 #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)])
175
176 /*
177  * Represent Extention Channel Offset in HT Capabilities
178  * This is available only in 40Mhz mode.
179  *   */
180 typedef enum _EXTCHNL_OFFSET {
181         EXTCHNL_OFFSET_NO_EXT = 0,
182         EXTCHNL_OFFSET_UPPER = 1,
183         EXTCHNL_OFFSET_NO_DEF = 2,
184         EXTCHNL_OFFSET_LOWER = 3,
185 } EXTCHNL_OFFSET, *PEXTCHNL_OFFSET;
186
187 typedef enum _VHT_DATA_SC {
188         VHT_DATA_SC_DONOT_CARE = 0,
189         VHT_DATA_SC_20_UPPER_OF_80MHZ = 1,
190         VHT_DATA_SC_20_LOWER_OF_80MHZ = 2,
191         VHT_DATA_SC_20_UPPERST_OF_80MHZ = 3,
192         VHT_DATA_SC_20_LOWEST_OF_80MHZ = 4,
193         VHT_DATA_SC_20_RECV1 = 5,
194         VHT_DATA_SC_20_RECV2 = 6,
195         VHT_DATA_SC_20_RECV3 = 7,
196         VHT_DATA_SC_20_RECV4 = 8,
197         VHT_DATA_SC_40_UPPER_OF_80MHZ = 9,
198         VHT_DATA_SC_40_LOWER_OF_80MHZ = 10,
199 } VHT_DATA_SC, *PVHT_DATA_SC_E;
200
201 typedef enum _PROTECTION_MODE {
202         PROTECTION_MODE_AUTO = 0,
203         PROTECTION_MODE_FORCE_ENABLE = 1,
204         PROTECTION_MODE_FORCE_DISABLE = 2,
205 } PROTECTION_MODE, *PPROTECTION_MODE;
206
207 typedef enum _RT_RF_TYPE_DEFINITION {
208         RF_1T2R = 0,
209         RF_2T4R = 1,
210         RF_2T2R = 2,
211         RF_1T1R = 3,
212         RF_2T2R_GREEN = 4,
213         RF_2T3R = 5,
214         RF_3T3R = 6,
215         RF_3T4R = 7,
216         RF_4T4R = 8,
217
218         RF_TYPE_AUTO,
219 } RT_RF_TYPE_DEF_E;
220
221 #define RF_TYPE_VALID(rf_type) (rf_type < RF_TYPE_AUTO)
222
223 extern const u8 _rf_type_to_rf_tx_cnt[];
224 #define rf_type_to_rf_tx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_tx_cnt[rf_type] : 0)
225
226 extern const u8 _rf_type_to_rf_rx_cnt[];
227 #define rf_type_to_rf_rx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_rx_cnt[rf_type] : 0)
228
229 int rtw_ch2freq(int chan);
230 int rtw_freq2ch(int freq);
231 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo);
232
233 #define RTW_MODULE_RTL8821AE_HMC_M2             BIT0 /* RTL8821AE(HMC + M.2) */
234 #define RTW_MODULE_RTL8821AU                    BIT1 /* RTL8821AU */
235 #define RTW_MODULE_RTL8812AENF_NGFF             BIT2 /* RTL8812AENF(8812AE+8761)_NGFF */
236 #define RTW_MODULE_RTL8812AEBT_HMC              BIT3 /* RTL8812AEBT(8812AE+8761)_HMC */
237 #define RTW_MODULE_RTL8188EE_HMC_M2             BIT4 /* RTL8188EE(HMC + M.2) */
238 #define RTW_MODULE_RTL8723BE_HMC_M2             BIT5 /* RTL8723BE(HMC + M.2) */
239 #define RTW_MODULE_RTL8723BS_NGFF1216   BIT6 /* RTL8723BS(NGFF1216) */
240 #define RTW_MODULE_RTL8192EEBT_HMC_M2   BIT7 /* RTL8192EEBT(8192EE+8761AU)_(HMC + M.2) */
241
242 #define IS_ALPHA2_NO_SPECIFIED(_alpha2) ((*((u16 *)(_alpha2))) == 0xFFFF)
243
244 struct country_chplan {
245         char alpha2[2];
246         u8 chplan;
247 #ifdef CONFIG_80211AC_VHT
248         u8 en_11ac;
249 #endif
250 #if RTW_DEF_MODULE_REGULATORY_CERT
251         u8 def_module_flags; /* RTW_MODULE_RTLXXX */
252 #endif
253 };
254
255 #ifdef CONFIG_80211AC_VHT
256 #define COUNTRY_CHPLAN_EN_11AC(_ent) ((_ent)->en_11ac)
257 #else
258 #define COUNTRY_CHPLAN_EN_11AC(_ent) 0
259 #endif
260
261 #if RTW_DEF_MODULE_REGULATORY_CERT
262 #define COUNTRY_CHPLAN_DEF_MODULE_FALGS(_ent) ((_ent)->def_module_flags)
263 #else
264 #define COUNTRY_CHPLAN_DEF_MODULE_FALGS(_ent) 0
265 #endif
266
267 const struct country_chplan *rtw_get_chplan_from_country(const char *country_code);
268
269 #define BB_GAIN_2G 0
270 #ifdef CONFIG_IEEE80211_BAND_5GHZ
271 #define BB_GAIN_5GLB1 1
272 #define BB_GAIN_5GLB2 2
273 #define BB_GAIN_5GMB1 3
274 #define BB_GAIN_5GMB2 4
275 #define BB_GAIN_5GHB 5
276 #endif
277
278 #ifdef CONFIG_IEEE80211_BAND_5GHZ
279 #define BB_GAIN_NUM 6
280 #else
281 #define BB_GAIN_NUM 1
282 #endif
283
284 int rtw_ch_to_bb_gain_sel(int ch);
285 void rtw_rf_set_tx_gain_offset(_adapter *adapter, u8 path, s8 offset);
286 void rtw_rf_apply_tx_gain_offset(_adapter *adapter, u8 ch);
287
288 bool rtw_is_dfs_range(u32 hi, u32 lo);
289 bool rtw_is_dfs_ch(u8 ch, u8 bw, u8 offset);
290 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region);
291 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region);
292
293 #endif /* _RTL8711_RF_H_ */