1 /****************************************************************************** 2 * 3 * Copyright(c) 2007 - 2019 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 68 u8 rtw_get_op_chs_by_cch_bw(u8 cch, u8 bw, u8 **op_chs, u8 *op_ch_num); 69 70 u8 rtw_get_offset_by_chbw(u8 ch, u8 bw, u8 *r_offset); 71 u8 rtw_get_center_ch(u8 ch, u8 bw, u8 offset); 72 73 u8 rtw_get_ch_group(u8 ch, u8 *group, u8 *cck_group); 74 75 typedef enum _CAPABILITY { 76 cESS = 0x0001, 77 cIBSS = 0x0002, 78 cPollable = 0x0004, 79 cPollReq = 0x0008, 80 cPrivacy = 0x0010, 81 cShortPreamble = 0x0020, 82 cPBCC = 0x0040, 83 cChannelAgility = 0x0080, 84 cSpectrumMgnt = 0x0100, 85 cQos = 0x0200, /* For HCCA, use with CF-Pollable and CF-PollReq */ 86 cShortSlotTime = 0x0400, 87 cAPSD = 0x0800, 88 cRM = 0x1000, /* RRM (Radio Request Measurement) */ 89 cDSSS_OFDM = 0x2000, 90 cDelayedBA = 0x4000, 91 cImmediateBA = 0x8000, 92 } CAPABILITY, *PCAPABILITY; 93 94 enum _REG_PREAMBLE_MODE { 95 PREAMBLE_LONG = 1, 96 PREAMBLE_AUTO = 2, 97 PREAMBLE_SHORT = 3, 98 }; 99 100 #define rf_path_char(path) (((path) >= RF_PATH_MAX) ? 'X' : 'A' + (path)) 101 102 #ifdef CONFIG_NARROWBAND_SUPPORTING 103 enum nb_config { 104 RTW_NB_CONFIG_NONE = 0, 105 RTW_NB_CONFIG_WIDTH_5 = 5, 106 RTW_NB_CONFIG_WIDTH_10 = 6, 107 }; 108 #endif 109 110 extern const char *const _rtw_band_str[]; 111 #define band_str(band) (((band) >= BAND_MAX) ? _rtw_band_str[BAND_MAX] : _rtw_band_str[(band)]) 112 113 extern const u8 _band_to_band_cap[]; 114 #define band_to_band_cap(band) (((band) >= BAND_MAX) ? _band_to_band_cap[BAND_MAX] : _band_to_band_cap[(band)]) 115 116 117 extern const char *const _ch_width_str[]; 118 #define ch_width_str(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_str[(bw)] : "CHANNEL_WIDTH_MAX") 119 120 extern const u8 _ch_width_to_bw_cap[]; 121 #define ch_width_to_bw_cap(bw) (((bw) < CHANNEL_WIDTH_MAX) ? _ch_width_to_bw_cap[(bw)] : 0) 122 123 enum opc_bw { 124 OPC_BW20 = 0, 125 OPC_BW40PLUS = 1, 126 OPC_BW40MINUS = 2, 127 OPC_BW80 = 3, 128 OPC_BW160 = 4, 129 OPC_BW80P80 = 5, 130 OPC_BW_NUM, 131 }; 132 133 extern const char *const _opc_bw_str[OPC_BW_NUM]; 134 #define opc_bw_str(bw) (((bw) < OPC_BW_NUM) ? _opc_bw_str[(bw)] : "N/A") 135 136 extern const u8 _opc_bw_to_ch_width[OPC_BW_NUM]; 137 #define opc_bw_to_ch_width(bw) (((bw) < OPC_BW_NUM) ? _opc_bw_to_ch_width[(bw)] : CHANNEL_WIDTH_MAX) 138 139 /* global op class APIs */ 140 bool is_valid_global_op_class_id(u8 gid); 141 s16 get_sub_op_class(u8 gid, u8 ch); 142 void dump_global_op_class(void *sel); 143 u8 rtw_get_op_class_by_chbw(u8 ch, u8 bw, u8 offset); 144 u8 rtw_get_bw_offset_by_op_class_ch(u8 gid, u8 ch, u8 *bw, u8 *offset); 145 146 struct op_ch_t { 147 u8 ch; 148 u8 static_non_op:1; /* not in channel list */ 149 u8 no_ir:1; 150 s16 max_txpwr; /* mBm */ 151 }; 152 153 struct op_class_pref_t { 154 u8 class_id; 155 enum band_type band; 156 enum opc_bw bw; 157 u8 ch_num; /* number of chs */ 158 u8 op_ch_num; /* channel number which is not static non operable */ 159 u8 ir_ch_num; /* channel number which can init radiation */ 160 struct op_ch_t chs[]; 161 }; 162 163 int op_class_pref_init(_adapter *adapter); 164 void op_class_pref_deinit(_adapter *adapter); 165 166 #define REG_BEACON_HINT 0 167 #define REG_TXPWR_CHANGE 1 168 #define REG_CHANGE 2 169 170 void op_class_pref_apply_regulatory(_adapter *adapter, u8 reason); 171 172 struct rf_ctl_t; 173 void dump_cap_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool detail); 174 void dump_reg_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool detail); 175 void dump_cur_spt_op_class_ch(void *sel, struct rf_ctl_t *rfctl, bool detail); 176 177 typedef enum _VHT_DATA_SC { 178 VHT_DATA_SC_DONOT_CARE = 0, 179 VHT_DATA_SC_20_UPPER_OF_80MHZ = 1, 180 VHT_DATA_SC_20_LOWER_OF_80MHZ = 2, 181 VHT_DATA_SC_20_UPPERST_OF_80MHZ = 3, 182 VHT_DATA_SC_20_LOWEST_OF_80MHZ = 4, 183 VHT_DATA_SC_20_RECV1 = 5, 184 VHT_DATA_SC_20_RECV2 = 6, 185 VHT_DATA_SC_20_RECV3 = 7, 186 VHT_DATA_SC_20_RECV4 = 8, 187 VHT_DATA_SC_40_UPPER_OF_80MHZ = 9, 188 VHT_DATA_SC_40_LOWER_OF_80MHZ = 10, 189 } VHT_DATA_SC, *PVHT_DATA_SC_E; 190 191 typedef enum _PROTECTION_MODE { 192 PROTECTION_MODE_AUTO = 0, 193 PROTECTION_MODE_FORCE_ENABLE = 1, 194 PROTECTION_MODE_FORCE_DISABLE = 2, 195 } PROTECTION_MODE, *PPROTECTION_MODE; 196 197 typedef enum _RF_TX_NUM { 198 RF_1TX = 0, 199 RF_2TX, 200 RF_3TX, 201 RF_4TX, 202 RF_MAX_TX_NUM, 203 RF_TX_NUM_NONIMPLEMENT, 204 } RF_TX_NUM; 205 206 #define RF_TYPE_VALID(rf_type) (rf_type < RF_TYPE_MAX) 207 208 extern const u8 _rf_type_to_rf_tx_cnt[]; 209 #define rf_type_to_rf_tx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_tx_cnt[rf_type] : 0) 210 211 extern const u8 _rf_type_to_rf_rx_cnt[]; 212 #define rf_type_to_rf_rx_cnt(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rf_rx_cnt[rf_type] : 0) 213 214 extern const char *const _rf_type_to_rfpath_str[]; 215 #define rf_type_to_rfpath_str(rf_type) (RF_TYPE_VALID(rf_type) ? _rf_type_to_rfpath_str[rf_type] : "UNKNOWN") 216 217 enum rf_type trx_num_to_rf_type(u8 tx_num, u8 rx_num); 218 enum rf_type trx_bmp_to_rf_type(u8 tx_bmp, u8 rx_bmp); 219 bool rf_type_is_a_in_b(enum rf_type a, enum rf_type b); 220 u8 rtw_restrict_trx_path_bmp_by_rftype(u8 trx_path_bmp, enum rf_type type, u8 *tx_num, u8 *rx_num); 221 222 #if CONFIG_IEEE80211_BAND_6GHZ 223 int rtw_6gch2freq(int chan); 224 #endif 225 226 int rtw_ch2freq(int chan); 227 int rtw_ch2freq_by_band(enum band_type band, int ch); 228 int rtw_freq2ch(int freq); 229 enum band_type rtw_freq2band(int freq); 230 bool rtw_freq_consecutive(int a, int b); 231 bool rtw_chbw_to_freq_range(u8 ch, u8 bw, u8 offset, u32 *hi, u32 *lo); 232 233 struct rf_ctl_t; 234 235 void txpwr_idx_get_dbm_str(s8 idx, u8 txgi_max, u8 txgi_pdbm, SIZE_T cwidth, char dbm_str[], u8 dbm_str_len); 236 237 #define MBM_PDBM 100 238 #define UNSPECIFIED_MBM 32767 /* maximum of s16 */ 239 240 void txpwr_mbm_get_dbm_str(s16 mbm, SIZE_T cwidth, char dbm_str[], u8 dbm_str_len); 241 s16 mb_of_ntx(u8 ntx); 242 243 #if CONFIG_TXPWR_LIMIT 244 void dump_regd_exc_list(void *sel, struct rf_ctl_t *rfctl); 245 void dump_txpwr_lmt(void *sel, _adapter *adapter); 246 #endif 247 248 /* only check channel ranges */ 249 #define rtw_is_2g_ch(ch) (ch >= 1 && ch <= 14) 250 #define rtw_is_5g_ch(ch) ((ch) >= 36 && (ch) <= 177) 251 #define rtw_is_same_band(a, b) \ 252 ((rtw_is_2g_ch(a) && rtw_is_2g_ch(b)) \ 253 || (rtw_is_5g_ch(a) && rtw_is_5g_ch(b))) 254 255 #define rtw_is_5g_band1(ch) ((ch) >= 36 && (ch) <= 48) 256 #define rtw_is_5g_band2(ch) ((ch) >= 52 && (ch) <= 64) 257 #define rtw_is_5g_band3(ch) ((ch) >= 100 && (ch) <= 144) 258 #define rtw_is_5g_band4(ch) ((ch) >= 149 && (ch) <= 177) 259 #define rtw_is_same_5g_band(a, b) \ 260 ((rtw_is_5g_band1(a) && rtw_is_5g_band1(b)) \ 261 || (rtw_is_5g_band2(a) && rtw_is_5g_band2(b)) \ 262 || (rtw_is_5g_band3(a) && rtw_is_5g_band3(b)) \ 263 || (rtw_is_5g_band4(a) && rtw_is_5g_band4(b))) 264 265 #define rtw_is_6g_band1(ch) ((ch) >= 1 && (ch) <= 93) 266 #define rtw_is_6g_band2(ch) ((ch) >= 97 && (ch) <= 117) 267 #define rtw_is_6g_band3(ch) ((ch) >= 121 && (ch) <= 189) 268 #define rtw_is_6g_band4(ch) ((ch) >= 193 && (ch) <= 237) 269 270 bool rtw_is_long_cac_range(u32 hi, u32 lo, u8 dfs_region); 271 bool rtw_is_long_cac_ch(u8 ch, u8 bw, u8 offset, u8 dfs_region); 272 273 #endif /* _RTL8711_RF_H_ */ 274